document capacity for ZST as example and prose

This commit is contained in:
Marijn Schouten 2025-01-30 12:51:22 +01:00 committed by Marijn Schouten
parent e6f12c8b7d
commit db7e61cfa5

View File

@ -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")]