-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Explicitly document the size guarantees that Option makes. #75454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
73ada2d
f5118a5
83f47aa
f3d7196
8cb8955
55802e3
68209c3
9bac577
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,10 +70,23 @@ | |
//! } | ||
//! ``` | ||
//! | ||
//! This usage of [`Option`] to create safe nullable pointers is so | ||
//! common that Rust does special optimizations to make the | ||
//! representation of [`Option`]`<`[`Box<T>`]`>` a single pointer. Optional pointers | ||
//! in Rust are stored as efficiently as any other pointer type. | ||
//! # Representation | ||
//! | ||
//! Rust guarantees to optimize the following types `<T>` such that an | ||
//! [`Option<T>`] has the same size as `T`: | ||
//! | ||
//! * [`Box<T>`] | ||
|
||
//! * `&T` | ||
//! * `&mut T` | ||
//! * `extern "C" fn` | ||
ltratt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
//! * [`num::NonZero*`] | ||
//! * [`ptr::NonNull<T>`] | ||
//! * `#[repr(transparent)]` struct around one of the types in this list. | ||
//! | ||
//! For the above cases, it is guaranteed that one can [`mem::transmute`] | ||
//! from all valid values of `T` to `Option<T>` but only from | ||
//! `Option::Some(T)` to `T` (i.e. transmuting `None` to `<T>` is undefined | ||
ltratt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
//! behaviour). | ||
//! | ||
//! # Examples | ||
//! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never saw
<T>
as notation for a type, not sure what that is supposed to indicate.