Use assertions on Vec doc

Clarify what the state of Vec after with_capacity on doc.
This commit is contained in:
Ivan Tham 2020-08-29 18:38:18 +08:00 committed by GitHub
parent 1dc748fb3d
commit 12b4cf8c6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,8 +116,10 @@ use crate::raw_vec::RawVec;
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
///
/// // The following is equivalent, but potentially slower:
/// let mut vec1 = Vec::with_capacity(5);
/// vec1.resize(5, 0);
/// let mut vec = Vec::with_capacity(5);
/// assert_eq!(vec, []);
/// vec.resize(5, 0);
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
/// ```
///
/// Use a `Vec<T>` as an efficient stack: