Skip to content

Commit 99a0f4d

Browse files
authored
Merge pull request #67 from jonas-schievink/countdown-cancel
Enable cancelable countdowns via a new `Cancel` trait
2 parents 5cc1bf8 + 3804ea8 commit 99a0f4d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/timer.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,17 @@ pub trait CountDown {
7979

8080
/// Marker trait that indicates that a timer is periodic
8181
pub trait Periodic {}
82+
83+
/// Trait for cancelable countdowns.
84+
pub trait Cancel : CountDown {
85+
/// Error returned when a countdown can't be canceled.
86+
type Error;
87+
88+
/// Tries to cancel this countdown.
89+
///
90+
/// # Errors
91+
///
92+
/// An error will be returned if the countdown has already been canceled or was never started.
93+
/// An error is also returned if the countdown is not `Periodic` and has already expired.
94+
fn cancel(&mut self) -> Result<(), Self::Error>;
95+
}

0 commit comments

Comments
 (0)