diff options
author | 2023-01-30 14:49:24 +0100 | |
---|---|---|
committer | 2023-02-01 09:10:30 +0100 | |
commit | ac891333f16371a036b19bed57d912b83be4a574 (patch) | |
tree | 08d852a543384320551899e6d70419bccd9ba3ed /rtic-common | |
parent | 6c48ebeeeeb5917251a4ba08d5c042cdd62e673d (diff) | |
download | rtic-ac891333f16371a036b19bed57d912b83be4a574.tar.gz rtic-ac891333f16371a036b19bed57d912b83be4a574.tar.zst rtic-ac891333f16371a036b19bed57d912b83be4a574.zip |
Add `rtic-arbiter`
Diffstat (limited to '')
-rw-r--r-- | rtic-common/src/dropper.rs | 26 | ||||
-rw-r--r-- | rtic-common/src/lib.rs | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/rtic-common/src/dropper.rs b/rtic-common/src/dropper.rs new file mode 100644 index 00000000..a4b4d159 --- /dev/null +++ b/rtic-common/src/dropper.rs @@ -0,0 +1,26 @@ +//! A drop implementation runner. + +/// Runs a closure on drop. +pub struct OnDrop<F: FnOnce()> { + f: core::mem::MaybeUninit<F>, +} + +impl<F: FnOnce()> OnDrop<F> { + /// Make a new droppper given a closure. + pub fn new(f: F) -> Self { + Self { + f: core::mem::MaybeUninit::new(f), + } + } + + /// Make it not run drop. + pub fn defuse(self) { + core::mem::forget(self) + } +} + +impl<F: FnOnce()> Drop for OnDrop<F> { + fn drop(&mut self) { + unsafe { self.f.as_ptr().read()() } + } +} diff --git a/rtic-common/src/lib.rs b/rtic-common/src/lib.rs index 3c75856c..b8b5e0d9 100644 --- a/rtic-common/src/lib.rs +++ b/rtic-common/src/lib.rs @@ -4,5 +4,6 @@ #![deny(missing_docs)] //deny_warnings_placeholder_for_ci +pub mod dropper; pub mod wait_queue; pub mod waker_registration; |