From 8b72dbabef78e9ab68abbdbdbc62a0332ca40d6f Mon Sep 17 00:00:00 2001 From: L0uisc Date: Wed, 11 Dec 2019 21:38:56 +0200 Subject: [PATCH] Implement into_boxed_slice() and doc-comment it. --- lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib.rs b/lib.rs index e919678..9b787ed 100644 --- a/lib.rs +++ b/lib.rs @@ -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 SmallVec { } } + /// 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),