Skip to content

Commit 80ed75c

Browse files
authored
document capacity for ZST as example
1 parent e6f12c8 commit 80ed75c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,17 @@ impl<T, A: Allocator> Vec<T, A> {
12401240
/// vec.push(42);
12411241
/// assert!(vec.capacity() >= 10);
12421242
/// ```
1243+
///
1244+
/// ```
1245+
/// #[derive(Clone)]
1246+
/// struct ZeroSized;
1247+
///
1248+
/// fn main() {
1249+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1250+
/// let v = vec![ZeroSized; 0];
1251+
/// assert_eq!(v.capacity(), usize::MAX);
1252+
/// }
1253+
/// ```
12431254
#[inline]
12441255
#[stable(feature = "rust1", since = "1.0.0")]
12451256
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]

0 commit comments

Comments
 (0)