MCPcopy Create free account
hub / github.com/hashintel/hash / dismiss

Method dismiss

libs/darwin-kperf/src/utils/drop_guard.rs:39–58  ·  view source on GitHub ↗
(guard: Self)

Source from the content-addressed store, hash-verified

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
61impl<T, F> Deref for DropGuard<T, F>

Callers 3

dismissNotificationFunction · 0.80
NotificationsProviderFunction · 0.80
AppFunction · 0.80

Calls 1

takeFunction · 0.85

Tested by

no test coverage detected