Skip to content

Commit f9490c8

Browse files
improve doc
1 parent 8a09420 commit f9490c8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,8 @@ impl<T, A: Allocator> Vec<T, A> {
10701070

10711071
/// Converts the vector into [`Box<[T]>`][owned slice].
10721072
///
1073-
/// Note that this will drop any excess capacity.
1073+
/// If the vector has excess capacity, its items will be moved into a
1074+
/// newly-allocated buffer with exactly the right capacity.
10741075
///
10751076
/// [owned slice]: Box
10761077
///
@@ -3223,6 +3224,14 @@ impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
32233224
/// ```
32243225
/// assert_eq!(Box::from(vec![1, 2, 3]), vec![1, 2, 3].into_boxed_slice());
32253226
/// ```
3227+
///
3228+
/// Any excess capacity is removed:
3229+
/// ```
3230+
/// let mut vec = Vec::with_capacity(10);
3231+
/// vec.extend([1, 2, 3]);
3232+
///
3233+
/// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice());
3234+
/// ```
32263235
fn from(v: Vec<T, A>) -> Self {
32273236
v.into_boxed_slice()
32283237
}

0 commit comments

Comments
 (0)