nrf/uarte: update to new api
This commit is contained in:
@ -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::*;
|
||||
|
24
embassy/src/util/on_drop.rs
Normal file
24
embassy/src/util/on_drop.rs
Normal 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()() }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user