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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use std::fmt::{self, Display};
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub struct NewName {
pub(crate) new_name: String,
pub(crate) returns_bool: ReturnsBool,
pub(crate) rule: NewNameRule,
}
impl NewName {
pub fn as_str(&self) -> &str {
self.new_name.as_str()
}
pub fn unwrap(self) -> String {
self.new_name
}
pub fn returns_bool(&self) -> ReturnsBool {
self.returns_bool
}
pub fn rule(&self) -> NewNameRule {
self.rule
}
pub fn is_fixed(&self) -> bool {
self.rule.is_fixed()
}
pub fn is_substituted(&self) -> bool {
self.rule.is_substituted()
}
pub fn is_regular(&self) -> bool {
self.rule.is_regular()
}
pub fn is_no_prefix(&self) -> bool {
self.rule.is_no_prefix()
}
}
impl Display for NewName {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}{} {}", self.returns_bool, self.rule, self.new_name)
}
}
impl<T: AsRef<str>> PartialEq<T> for NewName {
fn eq(&self, other: &T) -> bool {
self.as_str() == other.as_ref()
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum NewNameRule {
Fixed,
Regular,
NoPrefix,
Substituted,
}
impl NewNameRule {
pub fn is_fixed(&self) -> bool {
matches!(self, NewNameRule::Fixed)
}
pub fn is_substituted(&self) -> bool {
matches!(self, NewNameRule::Substituted)
}
pub fn is_regular(&self) -> bool {
matches!(self, NewNameRule::Regular)
}
pub fn is_no_prefix(&self) -> bool {
matches!(self, NewNameRule::NoPrefix)
}
}
impl Display for NewNameRule {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use NewNameRule::*;
match self {
Fixed => f.write_str("fixed as"),
Substituted => f.write_str("substituted with"),
NoPrefix => f.write_str("kept as"),
Regular => f.write_str("renamed as"),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ReturnsBool {
True,
False,
Maybe,
}
impl ReturnsBool {
pub fn is_true(&self) -> bool {
matches!(self, ReturnsBool::True)
}
pub fn is_false(&self) -> bool {
matches!(self, ReturnsBool::False)
}
pub fn is_maybe(&self) -> bool {
matches!(self, ReturnsBool::Maybe)
}
}
impl From<bool> for ReturnsBool {
fn from(returns_bool: bool) -> Self {
if returns_bool {
ReturnsBool::True
} else {
ReturnsBool::False
}
}
}
impl Display for ReturnsBool {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use ReturnsBool::*;
match self {
False => Ok(()),
True => f.write_str("-> bool "),
Maybe => f.write_str("-> ? "),
}
}
}