2 ms·
Yes, Rust's Guaranteed Niche Optimisation says if you make this: enum Foo<T> { Nasty, Nice(T), } ... and T has a niche, it is guaranteed that Foo<
by tialaramex 4y ago
Yes, Rust's Guaranteed Niche Optimisation says if you make this:
enum Foo<T> {
Nasty,
Nice(T),
}
... and T has a niche, it is guaranteed that Foo<T> has the same size as T and Nasty just slots into the niche.
In practice, other fancier things will get optimised, but Rust doesn't guarantee exactly what will or will not be handled, e.g. if the niche has room for four things, and I make an enum with four extra plain variants, the guarantee doesn't apply but probably that'll work.