Add ArrayVec::dispose()

This commit is contained in:
bluss
2015-12-22 08:07:18 +01:00
parent 455b28fd61
commit 440bcbf66b
+7 -3
View File
@@ -57,9 +57,7 @@ pub struct ArrayVec<A: Array> {
impl<A: Array> Drop for ArrayVec<A> { impl<A: Array> Drop for ArrayVec<A> {
fn drop(&mut self) { fn drop(&mut self) {
// clear all elements self.clear();
while let Some(_) = self.pop() {
}
// NoDrop inhibits array's drop // NoDrop inhibits array's drop
// panic safety: NoDrop::drop will trigger on panic, so the inner // panic safety: NoDrop::drop will trigger on panic, so the inner
@@ -340,6 +338,12 @@ impl<A: Array> ArrayVec<A> {
} }
} }
} }
/// Dispose of `self` without the overwriting that is needed in Drop.
pub fn dispose(mut self) {
self.clear();
mem::forget(self);
}
} }
impl<A: Array> Deref for ArrayVec<A> { impl<A: Array> Deref for ArrayVec<A> {