mirror of
https://github.com/openharmony/third_party_rust_rust-smallvec.git
synced 2026-07-21 01:55:25 -04:00
Implement into_boxed_slice() and doc-comment it.
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user