use anyhow::Result;
pub trait Poller {
fn poll(&mut self) -> Result<!>;
}
pub enum State<T = ()> {
Off,
On(Option<T>),
}
impl<T> State<T> {
pub const fn on() -> Self {
State::On(None)
}
#[must_use]
pub const fn off() -> Self {
State::Off
}
pub fn is_off(&self) -> bool {
matches!(self, State::Off)
}
pub fn is_on(&self) -> bool {
matches!(self, State::On(_))
}
pub fn toggle(&mut self) {
*self = match self {
State::On(_) => State::Off,
State::Off => State::On(None),
};
}
}
pub trait Switch {
fn toggle(&mut self) -> Result<()>;
}