From 29ab6b73e17af465bd9d25a6b59124f62c19f9f6 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Fri, 5 Jun 2020 01:11:01 +0800 Subject: [PATCH] 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. --- src/liballoc/vec.rs | 3 +++ 1 file changed, 3 insertions(+) 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 Vec { /// /// // 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]