Skip to content

Commit 596d1f2

Browse files
author
chansuke
committed
Add excess capacity description on Vec::leak
1 parent cfba499 commit 596d1f2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/alloc/src/vec/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,16 @@ impl<T, A: Allocator> Vec<T, A> {
17831783
/// static_ref[0] += 1;
17841784
/// assert_eq!(static_ref, &[2, 2, 3]);
17851785
/// ```
1786+
///
1787+
/// As well as `Vec::into_boxed_slice`, any excess capacity will be removed:
1788+
///
1789+
/// ```
1790+
/// let mut vec = Vec::with_capacity(10);
1791+
/// vec.extend([1, 2, 3].iter().cloned());
1792+
/// assert_eq!(vec.capacity(), 10);
1793+
/// let slice = vec.leak();
1794+
/// assert_eq!(slice.to_vec().capacity(), 3);
1795+
/// ```
17861796
#[stable(feature = "vec_leak", since = "1.47.0")]
17871797
#[inline]
17881798
pub fn leak<'a>(self) -> &'a mut [T]

0 commit comments

Comments
 (0)