Skip to content

Commit

Permalink
Auto merge of #190 - L0uisc:into-boxed-slice, r=mbrubeck
Browse files Browse the repository at this point in the history
Implement into_boxed_slice() and doc-comment it.

Implements `into_boxed_slice()` as per suggestion in #184.

I didn't write tests, since all I did was to call an existing method of `SmallVec`, `into_vec()` to create a `Vec` from it and then call a method of `alloc::vec::Vec`, `into_boxed_slice()` on the resulting `Vec`. Thus, nothing in my code needs testing, since it is trivially offloading to other methods.

I didn't, however, find a test exercising `into_vec()`, however. That is maybe something I can do? If so, can I get some pointers to where I should look for example tests and where my tests should live?

EDIT: Never mind, I forgot that unit tests are in the same file, so I scrutinized smallvec_ops.rs to search for a test for `into_vec()` and couldn't find it.
  • Loading branch information
bors-servo committed Dec 11, 2019
2 parents c1870ea + 8b72dba commit 731c0e9
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 731c0e9

Please sign in to comment.