File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -763,7 +763,11 @@ impl String {
763
763
self . vec . reserve_exact ( additional)
764
764
}
765
765
766
- /// Shrinks the capacity of this string buffer to match its length.
766
+ /// Shrinks the capacity of this string buffer to match its length as much
767
+ /// as possible.
768
+ ///
769
+ /// It will drop down as close as possible to the length but the allocator
770
+ /// may still inform the string that there is space for a few more bytes.
767
771
///
768
772
/// # Examples
769
773
///
@@ -772,7 +776,7 @@ impl String {
772
776
/// s.reserve(100);
773
777
/// assert!(s.capacity() >= 100);
774
778
/// s.shrink_to_fit();
775
- /// assert_eq !(s.capacity(), 3);
779
+ /// assert !(s.capacity() >= 3);
776
780
/// ```
777
781
#[ inline]
778
782
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -273,10 +273,13 @@ impl<T> Vec<T> {
273
273
/// assert_eq!(vec.len(), 0);
274
274
///
275
275
/// // These are all done without reallocating...
276
+ /// let cap = vec.capacity();
276
277
/// for i in 0..10 {
277
278
/// vec.push(i);
278
279
/// }
279
280
///
281
+ /// assert_eq!(vec.capacity(), cap);
282
+ ///
280
283
/// // ...but this may make the vector reallocate
281
284
/// vec.push(11);
282
285
/// ```
@@ -349,7 +352,7 @@ impl<T> Vec<T> {
349
352
///
350
353
/// ```
351
354
/// let vec: Vec<i32> = Vec::with_capacity(10);
352
- /// assert_eq !(vec.capacity(), 10);
355
+ /// assert !(vec.capacity() >= 10);
353
356
/// ```
354
357
#[ inline]
355
358
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -411,7 +414,7 @@ impl<T> Vec<T> {
411
414
/// ```
412
415
/// let mut vec = Vec::with_capacity(10);
413
416
/// vec.extend([1, 2, 3].iter().cloned());
414
- /// assert_eq !(vec.capacity(), 10);
417
+ /// assert !(vec.capacity() >= 10);
415
418
/// vec.shrink_to_fit();
416
419
/// assert!(vec.capacity() >= 3);
417
420
/// ```
You can’t perform that action at this time.
0 commit comments