#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Side {
Top,
Bottom,
Left,
Right,
}
impl Side {
pub fn parse(s: &str) -> Option<Self> {
Some(match s {
"top" => Self::Top,
"bottom" => Self::Bottom,
"left" => Self::Left,
"right" => Self::Right,
_ => return None,
})
}
pub fn index(self) -> u8 {
match self {
Side::Top => 0,
Side::Right => 1,
Side::Bottom => 2,
Side::Left => 3,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LinkOp {
pub line: LineStyle,
pub start: LinkMarker,
pub end: LinkMarker,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineStyle {
Solid, Dashed, Dotted, Wavy, }
impl LineStyle {
pub fn as_str(self) -> &'static str {
match self {
Self::Solid => "-",
Self::Dashed => "--",
Self::Dotted => "---",
Self::Wavy => "~",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LinkMarker {
#[default]
None,
Arrow, Crow, Dot, Diamond, One, ExactlyOne, ZeroOrOne, OneOrMany, ZeroOrMany, }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DrawOp {
Linear, Round, Angle, }
impl DrawOp {
pub fn as_str(self) -> &'static str {
match self {
Self::Linear => "(-)",
Self::Round => "(o)",
Self::Angle => "(<)",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChainOp {
Wire(LinkOp),
Measure(DrawOp),
Mate, }
impl ChainOp {
pub fn spelling(self) -> String {
match self {
Self::Wire(op) => format!(
"{}{}{}",
op.start.start_str(),
op.line.as_str(),
op.end.end_str()
),
Self::Measure(d) => d.as_str().to_string(),
Self::Mate => "||".to_string(),
}
}
pub fn wire(self) -> Option<LinkOp> {
match self {
Self::Wire(op) => Some(op),
_ => None,
}
}
}
impl LinkMarker {
pub fn start_str(self) -> &'static str {
match self {
Self::None => "",
Self::Arrow => "<",
Self::Crow => ">",
Self::Dot => "*",
Self::Diamond => "<>",
Self::One => "+",
Self::ExactlyOne => "++",
Self::ZeroOrOne => "+o",
Self::OneOrMany => ">+",
Self::ZeroOrMany => ">o",
}
}
pub fn end_str(self) -> &'static str {
match self {
Self::None => "",
Self::Arrow => ">",
Self::Crow => "<",
Self::Dot => "*",
Self::Diamond => "<>",
Self::One => "+",
Self::ExactlyOne => "++",
Self::ZeroOrOne => "o+",
Self::OneOrMany => "+<",
Self::ZeroOrMany => "o<",
}
}
}