(guard: Self)
| 37 | /// owned resources. |
| 38 | #[inline] |
| 39 | pub(crate) fn dismiss(guard: Self) -> T { |
| 40 | // First we ensure that dropping the guard will not trigger |
| 41 | // its destructor |
| 42 | let mut guard = ManuallyDrop::new(guard); |
| 43 | |
| 44 | // Next we manually read the stored value from the guard. |
| 45 | // |
| 46 | // SAFETY: this is safe because we've taken ownership of the guard. |
| 47 | let value = unsafe { ManuallyDrop::take(&mut guard.inner) }; |
| 48 | |
| 49 | // Finally we drop the stored closure. We do this *after* having read |
| 50 | // the value, so that even if the closure's `drop` function panics, |
| 51 | // unwinding still tries to drop the value. |
| 52 | // |
| 53 | // SAFETY: this is safe because we've taken ownership of the guard. |
| 54 | unsafe { |
| 55 | ManuallyDrop::drop(&mut guard.func); |
| 56 | } |
| 57 | value |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl<T, F> Deref for DropGuard<T, F> |
no test coverage detected