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