fix_getters_rules/
new_name.rs1use std::fmt::{self, Display};
4
5#[derive(Debug, PartialEq)]
9#[non_exhaustive]
10pub struct NewName {
11 pub(crate) new_name: String,
12 pub(crate) returns_bool: ReturnsBool,
13 pub(crate) rule: NewNameRule,
14}
15
16impl NewName {
17 pub fn as_str(&self) -> &str {
19 self.new_name.as_str()
20 }
21
22 pub fn unwrap(self) -> String {
24 self.new_name
25 }
26
27 pub fn returns_bool(&self) -> ReturnsBool {
29 self.returns_bool
30 }
31
32 pub fn rule(&self) -> NewNameRule {
34 self.rule
35 }
36
37 pub fn is_fixed(&self) -> bool {
41 self.rule.is_fixed()
42 }
43
44 pub fn is_substituted(&self) -> bool {
48 self.rule.is_substituted()
49 }
50
51 pub fn is_regular(&self) -> bool {
57 self.rule.is_regular()
58 }
59
60 pub fn is_no_prefix(&self) -> bool {
65 self.rule.is_no_prefix()
66 }
67}
68
69impl Display for NewName {
70 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
71 write!(f, "{}{} {}", self.returns_bool, self.rule, self.new_name)
72 }
73}
74
75impl<T: AsRef<str>> PartialEq<T> for NewName {
76 fn eq(&self, other: &T) -> bool {
77 self.as_str() == other.as_ref()
78 }
79}
80
81#[derive(Clone, Copy, Debug, PartialEq)]
83#[non_exhaustive]
84pub enum NewNameRule {
85 Fixed,
87 Regular,
89 NoPrefix,
91 Substituted,
93}
94
95impl NewNameRule {
96 pub fn is_fixed(&self) -> bool {
100 matches!(self, NewNameRule::Fixed)
101 }
102
103 pub fn is_substituted(&self) -> bool {
107 matches!(self, NewNameRule::Substituted)
108 }
109
110 pub fn is_regular(&self) -> bool {
116 matches!(self, NewNameRule::Regular)
117 }
118
119 pub fn is_no_prefix(&self) -> bool {
124 matches!(self, NewNameRule::NoPrefix)
125 }
126}
127
128impl Display for NewNameRule {
129 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
130 use NewNameRule::*;
131 match self {
132 Fixed => f.write_str("fixed as"),
133 Substituted => f.write_str("substituted with"),
134 NoPrefix => f.write_str("kept as"),
135 Regular => f.write_str("renamed as"),
136 }
137 }
138}
139
140#[derive(Debug, Copy, Clone, PartialEq)]
142pub enum ReturnsBool {
143 True,
144 False,
145 Maybe,
146}
147
148impl ReturnsBool {
149 pub fn is_true(&self) -> bool {
150 matches!(self, ReturnsBool::True)
151 }
152
153 pub fn is_false(&self) -> bool {
154 matches!(self, ReturnsBool::False)
155 }
156
157 pub fn is_maybe(&self) -> bool {
158 matches!(self, ReturnsBool::Maybe)
159 }
160}
161
162impl From<bool> for ReturnsBool {
163 fn from(returns_bool: bool) -> Self {
164 if returns_bool {
165 ReturnsBool::True
166 } else {
167 ReturnsBool::False
168 }
169 }
170}
171
172impl Display for ReturnsBool {
173 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
174 use ReturnsBool::*;
175 match self {
176 False => Ok(()),
177 True => f.write_str("-> bool "),
178 Maybe => f.write_str("-> ? "),
179 }
180 }
181}