Re:Java 17 / JDK 17: General Availability
by deepsun on Tuesday September 14, 2021 @11:30AM
(#28526319)
Sure, I meant:
Rust guarantees to optimize the following types T such that Option<T> has the same size as T:
Box<U>
&U
&mut U
fn, extern "C" fn
num::NonZero*
ptr::NonNull<U>
#[repr(transparent)] struct around one of the types in this list.
UPDATE: Or, better per your example:
struct T {i: i32} takes the same size as i32: https://play.rust-lang.org/?version=stable&mode=debug&editio...
That is not correct. Trivial counterexample:
https://play.rust-lang.org/?version=stable&mode=debug&editio...
prints
i.e. Option<T> is 4 bytes larger than plain T