mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Cleanup common code and clippy fixes
This commit is contained in:
parent
4c95224e72
commit
2a4218c8ff
3 changed files with 8 additions and 32 deletions
|
@ -142,8 +142,8 @@ where
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
TrySendError::NoReceiver(v) => write!(f, "NoReceiver({:?})", v),
|
TrySendError::NoReceiver(v) => write!(f, "NoReceiver({v:?})"),
|
||||||
TrySendError::Full(v) => write!(f, "Full({:?})", v),
|
TrySendError::Full(v) => write!(f, "Full({v:?})"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,14 +401,12 @@ impl<'a, T, const N: usize> Receiver<'a, T, N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(r)
|
Ok(r)
|
||||||
} else {
|
} else if self.is_closed() {
|
||||||
if self.is_closed() {
|
|
||||||
Err(ReceiveError::NoSender)
|
Err(ReceiveError::NoSender)
|
||||||
} else {
|
} else {
|
||||||
Err(ReceiveError::Empty)
|
Err(ReceiveError::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Receives a value, waiting if the queue is empty.
|
/// Receives a value, waiting if the queue is empty.
|
||||||
/// If all senders are dropped this will error with `NoSender`.
|
/// If all senders are dropped this will error with `NoSender`.
|
||||||
|
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
critical-section = "1"
|
critical-section = "1"
|
||||||
futures-util = { version = "0.3.25", default-features = false }
|
futures-util = { version = "0.3.25", default-features = false }
|
||||||
|
rtic-common = { version = "1.0.0", path = "../rtic-common" }
|
||||||
|
|
|
@ -14,13 +14,13 @@ use futures_util::{
|
||||||
future::{select, Either},
|
future::{select, Either},
|
||||||
pin_mut,
|
pin_mut,
|
||||||
};
|
};
|
||||||
|
use linked_list::{Link, LinkedList};
|
||||||
pub use monotonic::Monotonic;
|
pub use monotonic::Monotonic;
|
||||||
|
use rtic_common::dropper::OnDrop;
|
||||||
|
|
||||||
mod linked_list;
|
mod linked_list;
|
||||||
mod monotonic;
|
mod monotonic;
|
||||||
|
|
||||||
use linked_list::{Link, LinkedList};
|
|
||||||
|
|
||||||
/// Holds a waker and at which time instant this waker shall be awoken.
|
/// Holds a waker and at which time instant this waker shall be awoken.
|
||||||
struct WaitingWaker<Mono: Monotonic> {
|
struct WaitingWaker<Mono: Monotonic> {
|
||||||
waker: Waker,
|
waker: Waker,
|
||||||
|
@ -264,26 +264,3 @@ impl<Mono: Monotonic> TimerQueue<Mono> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OnDrop<F: FnOnce()> {
|
|
||||||
f: core::mem::MaybeUninit<F>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F: FnOnce()> OnDrop<F> {
|
|
||||||
pub fn new(f: F) -> Self {
|
|
||||||
Self {
|
|
||||||
f: core::mem::MaybeUninit::new(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
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()() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue