Skip to content

Commit 8b72dba

Browse files
committed
Implement into_boxed_slice() and doc-comment it.
1 parent c1870ea commit 8b72dba

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern crate alloc;
3737
#[cfg(any(test, feature = "write"))]
3838
extern crate std;
3939

40+
use alloc::boxed::Box;
4041
use alloc::vec::Vec;
4142
use core::borrow::{Borrow, BorrowMut};
4243
use core::cmp;
@@ -893,6 +894,14 @@ impl<A: Array> SmallVec<A> {
893894
}
894895
}
895896

897+
/// Converts a `SmallVec` into a `Box<[T]>` without reallocating if the `SmallVec` has already spilled
898+
/// onto the heap.
899+
///
900+
/// Note that this will drop any excess capacity.
901+
pub fn into_boxed_slice(self) -> Box<[A::Item]> {
902+
self.into_vec().into_boxed_slice()
903+
}
904+
896905
/// Convert the SmallVec into an `A` if possible. Otherwise return `Err(Self)`.
897906
///
898907
/// This method returns `Err(Self)` if the SmallVec is too short (and the `A` contains uninitialized elements),

0 commit comments

Comments
 (0)