Skip to content

Commit e324c25

Browse files
authored
Rollup merge of rust-lang#72986 - pickfire:vec-assert, r=Mark-Simulacrum
Add more assert to Vec with_capacity docs Show assertion on len too to show them how adding new items will affect both the length and capacity, before and after.
2 parents b584687 + 29ab6b7 commit e324c25

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/liballoc/vec.rs

+3
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,18 @@ impl<T> Vec<T> {
343343
///
344344
/// // The vector contains no items, even though it has capacity for more
345345
/// assert_eq!(vec.len(), 0);
346+
/// assert_eq!(vec.capacity(), 10);
346347
///
347348
/// // These are all done without reallocating...
348349
/// for i in 0..10 {
349350
/// vec.push(i);
350351
/// }
352+
/// assert_eq!(vec.len(), 10);
351353
/// assert_eq!(vec.capacity(), 10);
352354
///
353355
/// // ...but this may make the vector reallocate
354356
/// vec.push(11);
357+
/// assert_eq!(vec.len(), 11);
355358
/// assert!(vec.capacity() >= 11);
356359
/// ```
357360
#[inline]

0 commit comments

Comments
 (0)