use derive_more::with_trait::Display;
use super::{InStable, InTransition};
#[derive(Clone, Copy, Debug, Display, Eq, PartialEq)]
pub enum Stable {
Muted,
Unmuted,
}
impl Stable {
#[must_use]
pub const fn opposite(self) -> Self {
match self {
Self::Muted => Self::Unmuted,
Self::Unmuted => Self::Muted,
}
}
}
impl From<bool> for Stable {
fn from(muted: bool) -> Self {
if muted { Self::Muted } else { Self::Unmuted }
}
}
impl InStable for Stable {
type Transition = Transition;
fn start_transition(self) -> Self::Transition {
match self {
Self::Unmuted => Transition::Muting(self),
Self::Muted => Transition::Unmuting(self),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Transition {
Muting(Stable),
Unmuting(Stable),
}
impl InTransition for Transition {
type Stable = Stable;
fn intended(self) -> Self::Stable {
match self {
Self::Unmuting(_) => Stable::Unmuted,
Self::Muting(_) => Stable::Muted,
}
}
fn set_inner(self, inner: Self::Stable) -> Self {
match self {
Self::Unmuting(_) => Self::Unmuting(inner),
Self::Muting(_) => Self::Muting(inner),
}
}
fn into_inner(self) -> Self::Stable {
match self {
Self::Unmuting(s) | Self::Muting(s) => s,
}
}
fn opposite(self) -> Self {
match self {
Self::Unmuting(stable) => Self::Muting(stable),
Self::Muting(stable) => Self::Unmuting(stable),
}
}
}