Implement into_boxed_slice() and doc-comment it.

This commit is contained in:
L0uisc
2019-12-11 21:38:56 +02:00
parent d604f6010b
commit d9b9228da5
+9
View File
@@ -37,6 +37,7 @@ extern crate alloc;
#[cfg(any(test, feature = "write"))]
extern crate std;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::borrow::{Borrow, BorrowMut};
use core::cmp;
@@ -893,6 +894,14 @@ impl<A: Array> SmallVec<A> {
}
}
/// Converts a `SmallVec` into a `Box<[T]>` without reallocating if the `SmallVec` has already spilled
/// onto the heap.
///
/// Note that this will drop any excess capacity.
pub fn into_boxed_slice(self) -> Box<[A::Item]> {
self.into_vec().into_boxed_slice()
}
/// Convert the SmallVec into an `A` if possible. Otherwise return `Err(Self)`.
///
/// This method returns `Err(Self)` if the SmallVec is too short (and the `A` contains uninitialized elements),