Re:Announcing Rust 1.20
by __s on Thursday August 31, 2017 @08:26PM
(#15145203)
Problem is avoiding having to do Vec<Option<T>>
[ Parent
| on HN ]
If T is a reference type, doesn't Rust do an optimization where <Option<T>>> is implemented by using null pointers?
Yes. This optimization is expected to be expanded in the future but there are currently "NonZero" types. Rust notices this and uses the zero value as the enum descriminant.
So in this case the code generated is idential to a nullable pointer.
Yes, but that doesn't help when T is not a reference type.
If it's not a reference type, then the Option enum value is probably small relative to the rest of the data in the type.