mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
document capacity for ZST as example and prose
This commit is contained in:
parent
e6f12c8b7d
commit
db7e61cfa5
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user