mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 12:55:23 +01:00
Add rtic-arbiter
This commit is contained in:
parent
e65e532c2a
commit
5c1cefbf4e
7 changed files with 242 additions and 24 deletions
26
rtic-common/src/dropper.rs
Normal file
26
rtic-common/src/dropper.rs
Normal 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()() }
|
||||
}
|
||||
}
|
||||
|
|
@ -4,5 +4,6 @@
|
|||
#![deny(missing_docs)]
|
||||
//deny_warnings_placeholder_for_ci
|
||||
|
||||
pub mod dropper;
|
||||
pub mod wait_queue;
|
||||
pub mod waker_registration;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue