Add rtic-arbiter

This commit is contained in:
Emil Fresk 2023-01-30 14:49:24 +01:00 committed by Henrik Tjäder
parent e65e532c2a
commit 5c1cefbf4e
7 changed files with 242 additions and 24 deletions

View file

@ -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()() }
}
}

View file

@ -4,5 +4,6 @@
#![deny(missing_docs)]
//deny_warnings_placeholder_for_ci
pub mod dropper;
pub mod wait_queue;
pub mod waker_registration;