From d0c51269608c18a105fd010f070bd9af6f443c60 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 31 Jan 2023 22:05:43 +0100 Subject: [PATCH] Cleanup common code and clippy fixes --- rtic-channel/src/lib.rs | 12 +++++------- rtic-time/Cargo.toml | 1 + rtic-time/src/lib.rs | 27 ++------------------------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/rtic-channel/src/lib.rs b/rtic-channel/src/lib.rs index fef546b357..47e4a77d02 100644 --- a/rtic-channel/src/lib.rs +++ b/rtic-channel/src/lib.rs @@ -142,8 +142,8 @@ where { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - TrySendError::NoReceiver(v) => write!(f, "NoReceiver({:?})", v), - TrySendError::Full(v) => write!(f, "Full({:?})", v), + TrySendError::NoReceiver(v) => write!(f, "NoReceiver({v:?})"), + TrySendError::Full(v) => write!(f, "Full({v:?})"), } } } @@ -401,12 +401,10 @@ impl<'a, T, const N: usize> Receiver<'a, T, N> { } Ok(r) + } else if self.is_closed() { + Err(ReceiveError::NoSender) } else { - if self.is_closed() { - Err(ReceiveError::NoSender) - } else { - Err(ReceiveError::Empty) - } + Err(ReceiveError::Empty) } } diff --git a/rtic-time/Cargo.toml b/rtic-time/Cargo.toml index ea0593968b..dbcf45444a 100644 --- a/rtic-time/Cargo.toml +++ b/rtic-time/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] critical-section = "1" futures-util = { version = "0.3.25", default-features = false } +rtic-common = { version = "1.0.0", path = "../rtic-common" } diff --git a/rtic-time/src/lib.rs b/rtic-time/src/lib.rs index 44fdbcecfc..5e4457cc0e 100644 --- a/rtic-time/src/lib.rs +++ b/rtic-time/src/lib.rs @@ -14,13 +14,13 @@ use futures_util::{ future::{select, Either}, pin_mut, }; +use linked_list::{Link, LinkedList}; pub use monotonic::Monotonic; +use rtic_common::dropper::OnDrop; mod linked_list; mod monotonic; -use linked_list::{Link, LinkedList}; - /// Holds a waker and at which time instant this waker shall be awoken. struct WaitingWaker { waker: Waker, @@ -264,26 +264,3 @@ impl TimerQueue { } } } - -struct OnDrop { - f: core::mem::MaybeUninit, -} - -impl OnDrop { - pub fn new(f: F) -> Self { - Self { - f: core::mem::MaybeUninit::new(f), - } - } - - #[allow(unused)] - pub fn defuse(self) { - core::mem::forget(self) - } -} - -impl Drop for OnDrop { - fn drop(&mut self) { - unsafe { self.f.as_ptr().read()() } - } -}