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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! An [`Expr`].
use super::{field::Field, generic::TypeGeneric, method::Method};
/// An expression.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Expr {
/// A [`Method`].
Method(Method),
/// A [`TypeGeneric`].
Generic(TypeGeneric),
/// A [`Field`].
Field(Field),
/// Nothing.
None,
}
impl Expr {
/// Is this a method?
pub fn is_method(&self) -> bool {
if let Self::Method(_) = self {
true
} else {
false
}
}
/// Is this a generic?
pub fn is_generic(&self) -> bool {
if let Self::Generic(_) = self {
true
} else {
false
}
}
/// Is this a field?
pub fn is_field(&self) -> bool {
if let Self::Field(_) = self {
true
} else {
false
}
}
/// Is this none?
pub fn is_none(&self) -> bool {
self.clone() == Self::None
}
/// Get this as a method.
pub fn get_method(&self) -> Option<Method> {
if let Self::Method(m) = self {
Some(m.clone())
} else {
None
}
}
/// Get this as a generic.
pub fn get_generic(&self) -> Option<TypeGeneric> {
if let Self::Generic(g) = self {
Some(g.clone())
} else {
None
}
}
/// Get this as a field.
pub fn get_field(&self) -> Option<Field> {
if let Self::Field(f) = self {
Some(f.clone())
} else {
None
}
}
}