Add trait objects with static dispatch

One thing I look forward to seeing, once we have 2580-ptr-meta - The Rust RFC Book, is a "set of dyn Trait" container that groups by the metadata, storing the vtable only once per type that's actually used. Iterating that would then see runs of the same dynamic type, and thus branch prediction would work almost perfectly, removing most of the runtime overhead from the indirect calls.

Looks like this goes back to at least 2017 (pre-RFC: anonymous enums - #4 by Ixrec), if not earlier.

I do think it'd be nice, since it could also offer the obvious solution to things like if A { my_vec.into_iter() } else { a..b }, rather than manually needing to Either — data structures in Rust // Lib.rs

4 Likes