#[derive(Clone, Hash, PartialEq, Eq)]
pub struct Arrow {
pub arrows: Vec<ArrowShape>,
}
use self::ArrowShape::*;
impl Arrow {
pub fn is_default(&self) -> bool {
self.arrows.is_empty()
}
pub fn default() -> Arrow {
Arrow {
arrows: vec![],
}
}
pub fn none() -> Arrow {
Arrow {
arrows: vec![NoArrow],
}
}
pub fn normal() -> Arrow {
Arrow {
arrows: vec![ArrowShape::normal()]
}
}
pub fn from_arrow(arrow: ArrowShape) -> Arrow {
Arrow {
arrows: vec![arrow],
}
}
pub fn to_dot_string(&self) -> String {
let mut cow = String::new();
for arrow in &self.arrows {
cow.push_str(&arrow.to_dot_string());
};
cow
}
}
impl Into<Arrow> for [ArrowShape; 2] {
fn into(self) -> Arrow {
Arrow {
arrows: vec![self[0], self[1]],
}
}
}
impl Into<Arrow> for [ArrowShape; 3] {
fn into(self) -> Arrow {
Arrow {
arrows: vec![self[0], self[1], self[2]],
}
}
}
impl Into<Arrow> for [ArrowShape; 4] {
fn into(self) -> Arrow {
Arrow {
arrows: vec![self[0], self[1], self[2], self[3]],
}
}
}
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub enum Fill {
Open,
Filled,
}
impl Fill {
pub fn as_slice(self) -> &'static str {
match self {
Fill::Open => "o",
Fill::Filled => "",
}
}
}
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub enum Side {
Left,
Right,
Both,
}
impl Side {
pub fn as_slice(self) -> &'static str {
match self {
Side::Left => "l",
Side::Right => "r",
Side::Both => "",
}
}
}
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub enum ArrowShape {
NoArrow,
Normal(Fill, Side),
Box(Fill, Side),
Crow(Side),
Curve(Side),
ICurve(Fill, Side),
Diamond(Fill, Side),
Dot(Fill),
Inv(Fill, Side),
Tee(Side),
Vee(Side),
}
impl ArrowShape {
pub fn none() -> ArrowShape {
ArrowShape::NoArrow
}
pub fn normal() -> ArrowShape {
ArrowShape::Normal(Fill::Filled, Side::Both)
}
pub fn boxed() -> ArrowShape {
ArrowShape::Box(Fill::Filled, Side::Both)
}
pub fn crow() -> ArrowShape {
ArrowShape::Crow(Side::Both)
}
pub fn curve() -> ArrowShape {
ArrowShape::Curve(Side::Both)
}
pub fn icurve() -> ArrowShape {
ArrowShape::ICurve(Fill::Filled, Side::Both)
}
pub fn diamond() -> ArrowShape {
ArrowShape::Diamond(Fill::Filled, Side::Both)
}
pub fn dot() -> ArrowShape {
ArrowShape::Diamond(Fill::Filled, Side::Both)
}
pub fn inv() -> ArrowShape {
ArrowShape::Inv(Fill::Filled, Side::Both)
}
pub fn tee() -> ArrowShape {
ArrowShape::Tee(Side::Both)
}
pub fn vee() -> ArrowShape {
ArrowShape::Vee(Side::Both)
}
pub fn to_dot_string(&self) -> String {
let mut res = String::new();
match *self {
Box(fill, side) | ICurve(fill, side)| Diamond(fill, side) |
Inv(fill, side) | Normal(fill, side)=> {
res.push_str(fill.as_slice());
match side {
Side::Left | Side::Right => res.push_str(side.as_slice()),
Side::Both => {},
};
},
Dot(fill) => res.push_str(fill.as_slice()),
Crow(side) | Curve(side) | Tee(side)
| Vee(side) => {
match side {
Side::Left | Side::Right => res.push_str(side.as_slice()),
Side::Both => {},
}
}
NoArrow => {},
};
match *self {
NoArrow => res.push_str("none"),
Normal(_, _) => res.push_str("normal"),
Box(_, _) => res.push_str("box"),
Crow(_) => res.push_str("crow"),
Curve(_) => res.push_str("curve"),
ICurve(_, _) => res.push_str("icurve"),
Diamond(_, _) => res.push_str("diamond"),
Dot(_) => res.push_str("dot"),
Inv(_, _) => res.push_str("inv"),
Tee(_) => res.push_str("tee"),
Vee(_) => res.push_str("vee"),
};
res
}
}