Skip to content

Commit

Permalink
Make sleep function on trait Sleeper take a mutable reference
Browse files Browse the repository at this point in the history
Some sleepers, such as Delay from embedded-hal, might need mutable access to themselves to sleep.
  • Loading branch information
claudiomattera committed Nov 14, 2024
1 parent c568b23 commit 99f7c61
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub trait Instant: Clone + Copy + SubAssign<Duration> + AddAssign<Duration> {
/// A trait to abstract a sleep function
pub trait Sleeper {
/// Sleep for the specified duration
fn sleep(&self, duration: core::time::Duration);
fn sleep(&mut self, duration: core::time::Duration);
}

/// A trait to abstract an asynchronous sleep function
pub trait AsyncSleeper {
/// Sleep for the specified duration
#[allow(async_fn_in_trait)]
async fn sleep(&self, duration: core::time::Duration);
async fn sleep(&mut self, duration: core::time::Duration);
}

#[cfg(feature = "std")]
Expand All @@ -44,7 +44,7 @@ pub struct StdSleeper;

#[cfg(feature = "std")]
impl Sleeper for StdSleeper {
fn sleep(&self, duration: core::time::Duration) {
fn sleep(&mut self, duration: core::time::Duration) {
std::thread::sleep(duration)
}
}
Expand All @@ -56,7 +56,7 @@ pub struct SpinSleeper;

#[cfg(feature = "spin_sleep")]
impl Sleeper for SpinSleeper {
fn sleep(&self, duration: core::time::Duration) {
fn sleep(&mut self, duration: core::time::Duration) {
spin_sleep::sleep(duration)
}
}

0 comments on commit 99f7c61

Please sign in to comment.