diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 5168792092823..85237e5eccf08 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -201,6 +201,24 @@ use crate::raw_vec::RawVec; /// can be slow. For this reason, it is recommended to use [`Vec::with_capacity`] /// whenever possible to specify how big the vector is expected to get. /// +/// A vector containing the elements `'a'` and `'b'` with capacity 4 can be visualized as: +/// ```text +/// Stack ptr capacity len +/// +--------+--------+--------+ +/// | 0x0123 | 4 | 2 | +/// +--------+--------+--------+ +/// | +/// v +/// Heap +--------+--------+--------+--------+ +/// | 'a' | 'b' | uninit | uninit | +/// +--------+--------+--------+--------+ +/// ``` +/// +/// - **uninit** represents memory that is not initialized, see [`MaybeUninit`]. +/// - Note: the ABI is not stable and `Vec` makes no guarantees about its memory +/// layout (including the order of fields). See [the section about +/// guarantees](#guarantees). +/// /// # Guarantees /// /// Due to its incredibly fundamental nature, `Vec` makes a lot of guarantees @@ -294,6 +312,7 @@ use crate::raw_vec::RawVec; /// [`insert`]: Vec::insert /// [`reserve`]: Vec::reserve /// [owned slice]: Box +/// [`MaybeUninit`]: core::mem::MaybeUninit /// [slice]: ../../std/primitive.slice.html /// [`&`]: ../../std/primitive.reference.html #[stable(feature = "rust1", since = "1.0.0")]