nrf/uarte: update to new api

This commit is contained in:
Dario Nieuwenhuis
2021-03-22 01:15:44 +01:00
parent 7b6086d19e
commit df42c38492
5 changed files with 267 additions and 264 deletions

View File

@ -2,6 +2,7 @@
mod drop_bomb;
mod forever;
mod mutex;
mod on_drop;
mod portal;
mod signal;
@ -11,6 +12,7 @@ mod waker;
pub use drop_bomb::*;
pub use forever::*;
pub use mutex::*;
pub use on_drop::*;
pub use portal::*;
pub use signal::*;
pub use waker::*;

View File

@ -0,0 +1,24 @@
use core::mem;
use core::mem::MaybeUninit;
pub struct OnDrop<F: FnOnce()> {
f: MaybeUninit<F>,
}
impl<F: FnOnce()> OnDrop<F> {
pub fn new(f: F) -> Self {
Self {
f: MaybeUninit::new(f),
}
}
pub fn defuse(self) {
mem::forget(self)
}
}
impl<F: FnOnce()> Drop for OnDrop<F> {
fn drop(&mut self) {
unsafe { self.f.as_ptr().read()() }
}
}