use std::fmt;
use std::str::FromStr;
use anyhow::anyhow;
use crate::common::result::{Error, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Channel {
FL,
FR,
}
impl FromStr for Channel {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"FL" => Ok(Self::FL),
"FR" => Ok(Self::FR),
_ => Err(anyhow!("unsupported channel: {s}")),
}
}
}
impl fmt::Display for Channel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FL => write!(f, "FL"),
Self::FR => write!(f, "FR"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
In,
Out,
}
impl FromStr for Direction {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"in" => Ok(Self::In),
"out" => Ok(Self::Out),
_ => Err(anyhow!("unsupported direction: {s}")),
}
}
}
impl fmt::Display for Direction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::In => write!(f, "in"),
Self::Out => write!(f, "out"),
}
}
}