From 3804ea8067bcc4fc1cab01161ad782e3ecabc89a Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 26 Mar 2018 23:00:08 +0200 Subject: [PATCH] Add a `Cancel` trait for cancelable countdowns --- src/timer.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/timer.rs b/src/timer.rs index c7a31fec6..d760baf5f 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -77,3 +77,17 @@ pub trait CountDown { /// Marker trait that indicates that a timer is periodic pub trait Periodic {} + +/// Trait for cancelable countdowns. +pub trait Cancel : CountDown { + /// Error returned when a countdown can't be canceled. + type Error; + + /// Tries to cancel this countdown. + /// + /// # Errors + /// + /// An error will be returned if the countdown has already been canceled or was never started. + /// An error is also returned if the countdown is not `Periodic` and has already expired. + fn cancel(&mut self) -> Result<(), Self::Error>; +}