nodrop: Small improvement of into_inner
This commit is contained in:
+6
-4
@@ -24,10 +24,12 @@ impl<T> NoDrop<T> {
|
|||||||
/// Once extracted, the value can of course drop again.
|
/// Once extracted, the value can of course drop again.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_inner(mut self) -> T {
|
pub fn into_inner(mut self) -> T {
|
||||||
let inner_ptr = &mut *self;
|
let inner = unsafe {
|
||||||
unsafe {
|
ptr::read(&mut *self)
|
||||||
ptr::read(inner_ptr)
|
};
|
||||||
}
|
// skip Drop, so we don't even have to overwrite
|
||||||
|
mem::forget(self);
|
||||||
|
inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user