Clarify non-nullable pointer optimization in repr(C) section

pull/60/head
David A. Ramos 7 years ago
parent 557a2aa4b9
commit 68eb664b6a

@ -26,12 +26,11 @@ still consumes a byte of space.
* DST pointers (fat pointers), tuples, and enums with fields are not a concept * DST pointers (fat pointers), tuples, and enums with fields are not a concept
in C, and as such are never FFI-safe. in C, and as such are never FFI-safe.
* As an exception to the rule on enum with data, `Option<&T>` is * If `T` is an [FFI-safe non-nullable pointer
FFI-safe if `*const T` is FFI-safe, and they have the same type](ffi.html#the-nullable-pointer-optimization),
representation, using the null-pointer optimization: `Some<&T>` is `Option<T>` is guaranteed to have the same layout and ABI as `T` and is
represented as the pointer, and `None` is represented as a null therefore also FFI-safe. As of this writing, this covers `&`, `&mut`,
pointer. (This rule applies to any enum defined the same way as `Box`, and function pointers, all of which can never be null.
libcore's `Option` type, and using the default repr.)
* Tuple structs are like structs with regards to `repr(C)`, as the only * Tuple structs are like structs with regards to `repr(C)`, as the only
difference from a struct is that the fields arent named. difference from a struct is that the fields arent named.

Loading…
Cancel
Save