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
60
61
62
#[derive(
std::clone::Clone,
std::cmp::Eq,
std::cmp::Ord,
std::cmp::PartialEq,
std::cmp::PartialOrd,
std::fmt::Debug,
std::hash::Hash,
)]
pub enum Kind {
Anchor,
NonAnchor,
Unknown(String),
}
impl std::convert::From<&str> for Kind {
fn from(s: &str) -> Self {
match s {
"anchor" => Kind::Anchor,
"non-anchor" => Kind::NonAnchor,
"non_anchor" => Kind::NonAnchor,
other => Kind::Unknown(other.to_owned()),
}
}
}
impl std::str::FromStr for Kind {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(Kind::from(s))
}
}
impl Kind {
pub fn as_str(&self) -> &str {
match self {
Kind::Anchor => "anchor",
Kind::NonAnchor => "non-anchor",
Kind::Unknown(s) => s.as_ref(),
}
}
pub fn values() -> &'static [&'static str] {
&[
"anchor", "non-anchor", ]
}
}
impl AsRef<str> for Kind {
fn as_ref(&self) -> &str {
self.as_str()
}
}