Far cleaner and more reliable than the old doc-link pattern. Also allowed me to spot some event types and sources which should have been made non_exhaustive.
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
/// Playback status of a track.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub enum PlayMode {
|
|
/// The track is currently playing.
|
|
Play,
|
|
/// The track is currently paused, and may be resumed.
|
|
Pause,
|
|
/// The track has been manually stopped, and cannot be restarted.
|
|
Stop,
|
|
/// The track has naturally ended, and cannot be restarted.
|
|
End,
|
|
}
|
|
|
|
impl PlayMode {
|
|
/// Returns whether the track has irreversibly stopped.
|
|
pub fn is_done(self) -> bool {
|
|
matches!(self, PlayMode::Stop | PlayMode::End)
|
|
}
|
|
|
|
pub(crate) fn change_to(self, other: Self) -> PlayMode {
|
|
use PlayMode::*;
|
|
|
|
// Idea: a finished track cannot be restarted -- this action is final.
|
|
// We may want to change this in future so that seekable tracks can uncancel
|
|
// themselves, perhaps, but this requires a bit more machinery to readd...
|
|
match self {
|
|
Play | Pause => other,
|
|
state => state,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for PlayMode {
|
|
fn default() -> Self {
|
|
PlayMode::Play
|
|
}
|
|
}
|