From 440bcbf66b82d26e29bd3b801112055edb016aca Mon Sep 17 00:00:00 2001 From: bluss Date: Tue, 22 Dec 2015 08:07:18 +0100 Subject: [PATCH] Add ArrayVec::dispose() --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 {