leptos_chartistry/
edge.rs1use std::str::FromStr;
2
3#[derive(Copy, Clone, Debug, PartialEq)]
5pub enum Edge {
6 Top,
8 Right,
10 Bottom,
12 Left,
14}
15
16impl Edge {
17 pub fn is_horizontal(&self) -> bool {
19 match self {
20 Self::Top | Self::Bottom => true,
21 Self::Right | Self::Left => false,
22 }
23 }
24
25 pub fn is_vertical(&self) -> bool {
27 !self.is_horizontal()
28 }
29}
30
31impl std::fmt::Display for Edge {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 Self::Top => write!(f, "top"),
35 Self::Right => write!(f, "right"),
36 Self::Bottom => write!(f, "bottom"),
37 Self::Left => write!(f, "left"),
38 }
39 }
40}
41
42impl FromStr for Edge {
43 type Err = String;
44
45 fn from_str(s: &str) -> Result<Self, Self::Err> {
46 match s.to_lowercase().as_str() {
47 "top" => Ok(Self::Top),
48 "right" => Ok(Self::Right),
49 "bottom" => Ok(Self::Bottom),
50 "left" => Ok(Self::Left),
51 _ => Err(format!("unknown edge: `{}`", s)),
52 }
53 }
54}