feat: API additions

This commit is contained in:
Conrad Ludgate
2021-05-25 21:57:59 +01:00
parent 7b290b7aa5
commit 8778483b12
+20 -5
View File
@@ -636,14 +636,29 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
if self.len() < self.capacity() {
Err(self)
} else {
unsafe {
let self_ = ManuallyDrop::new(self);
let array = ptr::read(self_.as_ptr() as *const [T; CAP]);
Ok(array)
}
unsafe { Ok(self.into_inner_unchecked()) }
}
}
pub unsafe fn into_inner_unchecked(self) -> [T; CAP] {
let self_ = ManuallyDrop::new(self);
let array = ptr::read(self_.as_ptr() as *const [T; CAP]);
array
}
pub fn take(&mut self) -> Option<[T; CAP]> {
if self.len() < self.capacity() {
None
} else {
unsafe { Some(self.take_unchecked()) }
}
}
pub unsafe fn take_unchecked(&mut self) -> [T; CAP] {
let data = std::mem::replace(self, Self::new());
data.into_inner_unchecked()
}
/// Return a slice containing all elements of the vector.
pub fn as_slice(&self) -> &[T] {
ArrayVecImpl::as_slice(self)