diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-12-03 12:51:27 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-03 12:51:27 +0900 |
| commit | 9f3ccd4bf642d9c55582bd643ec33b8a726272d6 (patch) | |
| tree | 45b7c907af1f877d25ab95ad30f124c98e392f16 | |
| parent | 52e886279a9ec14ccf06de563c3281740c6f0e9c (diff) | |
| parent | f9490c81219c78dc64d9f1c8578b7a9f3fa06833 (diff) | |
| download | rust-9f3ccd4bf642d9c55582bd643ec33b8a726272d6.tar.gz rust-9f3ccd4bf642d9c55582bd643ec33b8a726272d6.zip | |
Rollup merge of #105032 - HintringerFabian:improve_docs, r=JohnTitor
improve doc of into_boxed_slice and impl From<Vec<T>> for Box<[T]> Improves description of `into_boxed_slice`, and adds example to `impl From<Vec<T>> for Box<[T]>`. Fixes #98908
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index e147af2ce39..ba34ab6800f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1070,7 +1070,8 @@ impl<T, A: Allocator> Vec<T, A> { /// Converts the vector into [`Box<[T]>`][owned slice]. /// - /// Note that this will drop any excess capacity. + /// If the vector has excess capacity, its items will be moved into a + /// newly-allocated buffer with exactly the right capacity. /// /// [owned slice]: Box /// @@ -3223,6 +3224,14 @@ impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> { /// ``` /// assert_eq!(Box::from(vec![1, 2, 3]), vec![1, 2, 3].into_boxed_slice()); /// ``` + /// + /// Any excess capacity is removed: + /// ``` + /// let mut vec = Vec::with_capacity(10); + /// vec.extend([1, 2, 3]); + /// + /// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice()); + /// ``` fn from(v: Vec<T, A>) -> Self { v.into_boxed_slice() } |
