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
This commit is contained in:
commit
c7700406f4
1 changed files with 13 additions and 0 deletions
|
@ -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")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue