about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
diff options
context:
space:
mode:
authorIvan Tham <pickfire@riseup.net>2020-06-05 01:11:01 +0800
committerIvan Tham <pickfire@riseup.net>2020-06-05 01:11:01 +0800
commit29ab6b73e17af465bd9d25a6b59124f62c19f9f6 (patch)
tree15a6b9c46ee3621743f40604a1bcd576ddeb81d8 /src/liballoc/vec.rs
parent2a5cbb0e42f330617a061243f8725d861dd5118b (diff)
downloadrust-29ab6b73e17af465bd9d25a6b59124f62c19f9f6.tar.gz
rust-29ab6b73e17af465bd9d25a6b59124f62c19f9f6.zip
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.
Diffstat (limited to 'src/liballoc/vec.rs')
-rw-r--r--src/liballoc/vec.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 22d43468771..ffae3b5c789 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -343,15 +343,18 @@ impl<T> Vec<T> {
     ///
     /// // The vector contains no items, even though it has capacity for more
     /// assert_eq!(vec.len(), 0);
+    /// assert_eq!(vec.capacity(), 10);
     ///
     /// // These are all done without reallocating...
     /// for i in 0..10 {
     ///     vec.push(i);
     /// }
+    /// assert_eq!(vec.len(), 10);
     /// assert_eq!(vec.capacity(), 10);
     ///
     /// // ...but this may make the vector reallocate
     /// vec.push(11);
+    /// assert_eq!(vec.len(), 11);
     /// assert!(vec.capacity() >= 11);
     /// ```
     #[inline]