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