update take
This commit is contained in:
+2
-11
@@ -646,17 +646,8 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
|
|||||||
array
|
array
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take(&mut self) -> Option<[T; CAP]> {
|
pub fn take(&mut self) -> Self {
|
||||||
if self.len() < self.capacity() {
|
mem::replace(self, Self::new())
|
||||||
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.
|
/// Return a slice containing all elements of the vector.
|
||||||
|
|||||||
Reference in New Issue
Block a user