diff --git a/src/lib.rs b/src/lib.rs index ea20055..2dca9de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,9 +57,7 @@ pub struct ArrayVec { impl Drop for ArrayVec { fn drop(&mut self) { - // clear all elements - while let Some(_) = self.pop() { - } + self.clear(); // NoDrop inhibits array's drop // panic safety: NoDrop::drop will trigger on panic, so the inner @@ -340,6 +338,12 @@ impl ArrayVec { } } } + + /// Dispose of `self` without the overwriting that is needed in Drop. + pub fn dispose(mut self) { + self.clear(); + mem::forget(self); + } } impl Deref for ArrayVec {