diff options
| author | Ivan Tham <pickfire@riseup.net> | 2020-06-05 01:11:01 +0800 |
|---|---|---|
| committer | Ivan Tham <pickfire@riseup.net> | 2020-06-05 01:11:01 +0800 |
| commit | 29ab6b73e17af465bd9d25a6b59124f62c19f9f6 (patch) | |
| tree | 15a6b9c46ee3621743f40604a1bcd576ddeb81d8 /src/liballoc | |
| parent | 2a5cbb0e42f330617a061243f8725d861dd5118b (diff) | |
| download | rust-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')
| -rw-r--r-- | src/liballoc/vec.rs | 3 |
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] |
