grass_runtime/property/
strand.rs

1use std::fmt::Display;
2
3#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub enum Strand {
5    Negative,
6    Positive,
7    Unknown,
8}
9
10impl Strand {
11    pub fn is_positive(&self) -> bool {
12        matches!(self, Strand::Positive)
13    }
14    pub fn is_negative(&self) -> bool {
15        matches!(self, Strand::Negative)
16    }
17}
18
19impl Display for Strand {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            Self::Positive => write!(f, "+"),
23            Self::Negative => write!(f, "-"),
24            Self::Unknown => write!(f, "."),
25        }
26    }
27}
28
29impl<'a> PartialEq<&'a str> for Strand {
30    fn eq(&self, other: &&'a str) -> bool {
31        match self {
32            Self::Positive => *other == "+",
33            Self::Negative => *other == "-",
34            Self::Unknown => *other == ".",
35        }
36    }
37}
38
39pub trait Stranded {
40    fn strand(&self) -> Strand {
41        Strand::Unknown
42    }
43}
44
45impl<T: Stranded> Stranded for Option<T> {
46    fn strand(&self) -> Strand {
47        if let Some(inner) = self.as_ref() {
48            inner.strand()
49        } else {
50            Strand::Unknown
51        }
52    }
53}
54
55impl<A: Stranded, B> Stranded for (A, B) {
56    fn strand(&self) -> Strand {
57        self.0.strand()
58    }
59}