tests + docs

This commit is contained in:
Conrad Ludgate
2021-05-29 13:01:14 +01:00
parent 6dc46b3a1c
commit 16c8e4d40d
2 changed files with 37 additions and 0 deletions
+13
View File
@@ -640,12 +640,25 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
}
}
/// Return the inner fixed size array.
///
/// Safety:
/// This operation is safe if and only if length equals capacity.
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
}
/// Returns the ArrayVec, replacing the original with a new empty ArrayVec.
///
/// ```
/// use arrayvec::ArrayVec;
///
/// let mut v = ArrayVec::from([0, 1, 2, 3]);
/// assert_eq!([0, 1, 2, 3], v.take().into_inner().unwrap());
/// assert!(v.is_empty());
/// ```
pub fn take(&mut self) -> Self {
mem::replace(self, Self::new())
}