Skip to content

Commit 3804ea8

Browse files
Add a Cancel trait for cancelable countdowns
1 parent 65319b2 commit 3804ea8

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
@@ -77,3 +77,17 @@ pub trait CountDown {
7777

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

0 commit comments

Comments
 (0)