-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable cancelable countdowns via a new Cancel
trait
#67
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo. Should be "cancelled" (one "l" missing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, just found out that this is a British vs. American English thing. Feel free to disregard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I had to look this up, too. Decided to go with American English since most internationally used words in computer science and engineering use their AE spelling in favor of BE. |
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if the documentation should be that specific. Maybe setting I'm unsure. Unless others have stronger opinions, I'd feel more comfortable if the documentation were less definitive ("Possible error conditions include ...", something like that). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what you say is the right approach for most traits If the error conditions were unclear, applications would have to
This comes with another problem: If this is done, applications can no longer use So yeah, I think defining the error conditions to some extent is required for this to be useful at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, that makes a lot of sense. In that case we should consider whether pre-defining an error enum (instead of having the associated type) would be a good idea. In the interest of moving things along, I consider that a question for later though. I'll open follow-up issues tomorrow and will make sure to mention that. |
||
fn cancel(&mut self) -> Result<(), Self::Error>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍