use std::str::FromStr;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Edge {
Top,
Right,
Bottom,
Left,
}
impl Edge {
pub fn is_horizontal(&self) -> bool {
match self {
Self::Top | Self::Bottom => true,
Self::Right | Self::Left => false,
}
}
pub fn is_vertical(&self) -> bool {
!self.is_horizontal()
}
}
impl std::fmt::Display for Edge {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Top => write!(f, "top"),
Self::Right => write!(f, "right"),
Self::Bottom => write!(f, "bottom"),
Self::Left => write!(f, "left"),
}
}
}
impl FromStr for Edge {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"top" => Ok(Self::Top),
"right" => Ok(Self::Right),
"bottom" => Ok(Self::Bottom),
"left" => Ok(Self::Left),
_ => Err(format!("unknown edge: `{}`", s)),
}
}
}