Rollup merge of #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.
This commit is contained in:
commit
e324c25fff
@ -343,15 +343,18 @@ impl<T> Vec<T> {
|
|||||||
///
|
///
|
||||||
/// // The vector contains no items, even though it has capacity for more
|
/// // The vector contains no items, even though it has capacity for more
|
||||||
/// assert_eq!(vec.len(), 0);
|
/// assert_eq!(vec.len(), 0);
|
||||||
|
/// assert_eq!(vec.capacity(), 10);
|
||||||
///
|
///
|
||||||
/// // These are all done without reallocating...
|
/// // These are all done without reallocating...
|
||||||
/// for i in 0..10 {
|
/// for i in 0..10 {
|
||||||
/// vec.push(i);
|
/// vec.push(i);
|
||||||
/// }
|
/// }
|
||||||
|
/// assert_eq!(vec.len(), 10);
|
||||||
/// assert_eq!(vec.capacity(), 10);
|
/// assert_eq!(vec.capacity(), 10);
|
||||||
///
|
///
|
||||||
/// // ...but this may make the vector reallocate
|
/// // ...but this may make the vector reallocate
|
||||||
/// vec.push(11);
|
/// vec.push(11);
|
||||||
|
/// assert_eq!(vec.len(), 11);
|
||||||
/// assert!(vec.capacity() >= 11);
|
/// assert!(vec.capacity() >= 11);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user