diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-03-16 21:47:42 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-16 21:47:42 -0400 |
| commit | c7700406f4536d0dd0376483584c24e439aa139a (patch) | |
| tree | 11ab2a87a49343d743286d5c44d90bdc5d0cdf3e /library/alloc/src/vec/mod.rs | |
| parent | 227690a258492c84ae9927d18289208d0180e62f (diff) | |
| parent | db7e61cfa53f72f1be9179180272b836bf781a40 (diff) | |
| download | rust-c7700406f4536d0dd0376483584c24e439aa139a.tar.gz rust-c7700406f4536d0dd0376483584c24e439aa139a.zip | |
Rollup merge of #136293 - hkBst:patch-32, r=Amanieu
document capacity for ZST as example The main text already covers this, although it provides weaker guarantees, but I think an example in the right spot does not hurt. Fixes #80747
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
| -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 da9a77154f9..3782f9e9519 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1252,6 +1252,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_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")] |
