Skip to content
/ rust Public
forked from rust-lang/rust

Commit db7e61c

Browse files
committed
document capacity for ZST as example and prose
1 parent e6f12c8 commit db7e61c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/alloc/src/vec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,19 @@ impl<T, A: Allocator> Vec<T, A> {
12401240
/// vec.push(42);
12411241
/// assert!(vec.capacity() >= 10);
12421242
/// ```
1243+
///
1244+
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
1245+
///
1246+
/// ```
1247+
/// #[derive(Clone)]
1248+
/// struct ZeroSized;
1249+
///
1250+
/// fn main() {
1251+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1252+
/// let v = vec![ZeroSized; 0];
1253+
/// assert_eq!(v.capacity(), usize::MAX);
1254+
/// }
1255+
/// ```
12431256
#[inline]
12441257
#[stable(feature = "rust1", since = "1.0.0")]
12451258
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]

0 commit comments

Comments
 (0)