diff options
| author | Marijn Schouten <hkBst@users.noreply.github.com> | 2025-01-30 12:51:22 +0100 |
|---|---|---|
| committer | Marijn Schouten <mhkbst@gmail.com> | 2025-03-09 13:11:51 +0100 |
| commit | db7e61cfa53f72f1be9179180272b836bf781a40 (patch) | |
| tree | c69d999893b0bfa2e7494d367b09ff33eb69bb9c /library/alloc/src/vec | |
| parent | e6f12c8b7d8d5c821c32fb2739ea01d1d874c58a (diff) | |
| download | rust-db7e61cfa53f72f1be9179180272b836bf781a40.tar.gz rust-db7e61cfa53f72f1be9179180272b836bf781a40.zip | |
document capacity for ZST as example and prose
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 48afcf6e064..0aacdd2fc5b 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1240,6 +1240,19 @@ impl<T, A: Allocator> Vec<T, A> { /// vec.push(42); /// assert!(vec.capacity() >= 10); /// ``` + /// + /// A vector with zero-sized elements will always have a capacity of usize::MAX: + /// + /// ``` + /// #[derive(Clone)] + /// struct ZeroSized; + /// + /// fn main() { + /// assert_eq!(std::mem::size_of::<ZeroSized>(), 0); + /// let v = vec![ZeroSized; 0]; + /// assert_eq!(v.capacity(), usize::MAX); + /// } + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")] |
