Skip to content

Commit

Permalink
Implement into_boxed_slice() and doc-comment it.
Browse files Browse the repository at this point in the history
  • Loading branch information
L0uisc committed Dec 11, 2019
1 parent c1870ea commit 8b72dba
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 8b72dba

Please sign in to comment.