| 1 | //! Would-be-getter rename attempt sucessful result and details. |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#}; |
| 4 | |
| 5 | /// Would-be-getter rename attempt sucessful result and details. |
| 6 | /// |
| 7 | /// Holds details about what happened and assumptions on the return type. |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 9 | #[non_exhaustive] |
| 10 | pub struct NewNamerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName# { |
| 11 | pub(craterust-analyzer cargo fix-getters-rules 0.3.2 crate/) new_namerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#new_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 12 | pub(craterust-analyzer cargo fix-getters-rules 0.3.2 crate/) returns_boolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#returns_bool.: ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#, |
| 13 | pub(craterust-analyzer cargo fix-getters-rules 0.3.2 crate/) rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule.: NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#, |
| 14 | } |
| 15 | |
| 16 | impl NewNamerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName# { |
| 17 | /// Returns the new name. |
| 18 | pub fn as_strrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]as_str().(&self) -> &str { |
| 19 | self.new_namerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#new_name..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() |
| 20 | } |
| 21 | |
| 22 | /// Consumes the [`NewName`] and returns the inner new name [`String`]. |
| 23 | pub fn unwraprust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]unwrap().(self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 24 | self.new_namerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#new_name. |
| 25 | } |
| 26 | |
| 27 | /// Returns current knowledge about the getter returning exactly one `bool`. |
| 28 | pub fn returns_boolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]returns_bool().(&self) -> ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool# { |
| 29 | self.returns_boolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#returns_bool. |
| 30 | } |
| 31 | |
| 32 | /// Returns the renaming rule that was used to rename the getter. |
| 33 | pub fn rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]rule().(&self) -> NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule# { |
| 34 | self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule. |
| 35 | } |
| 36 | |
| 37 | /// Returns whether renaming required fixing the name to comply with rules. |
| 38 | /// |
| 39 | /// Ex. `get_mut_structure` -> `structure_mut`. |
| 40 | pub fn is_fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]is_fixed().(&self) -> bool { |
| 41 | self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule..is_fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_fixed().() |
| 42 | } |
| 43 | |
| 44 | /// Returns whether renaming required substituing (part) of the name. |
| 45 | /// |
| 46 | /// Ex. `get_mute` -> `is_muted`. |
| 47 | pub fn is_substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]is_substituted().(&self) -> bool { |
| 48 | self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule..is_substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_substituted().() |
| 49 | } |
| 50 | |
| 51 | /// Returns whether renaming used the regular strategy. |
| 52 | /// |
| 53 | /// Ex.: |
| 54 | /// * `get_name` -> `name`. |
| 55 | /// * `get_active` -> `is_active`. |
| 56 | pub fn is_regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]is_regular().(&self) -> bool { |
| 57 | self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule..is_regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_regular().() |
| 58 | } |
| 59 | |
| 60 | /// Returns whether renaming didn't use the `is` prefix for `bool` getter. |
| 61 | /// |
| 62 | /// Ex.: |
| 63 | /// * `get_has_entry` -> `has_entry`. |
| 64 | pub fn is_no_prefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]is_no_prefix().(&self) -> bool { |
| 65 | self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule..is_no_prefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_no_prefix().() |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for NewNamerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName# { |
| 70 | fn fmtrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 71 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}{} {}", self.returns_boolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#returns_bool., self.rulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#rule., self.new_namerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName#new_name.) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<T> for NewNamerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewName# { |
| 76 | fn eqrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName][`PartialEq<T>`]eq().(&self, other: &T) -> bool { |
| 77 | self.as_strrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewName]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().() |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /// Rule that applied to get the [`NewName`]. |
| 82 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 83 | #[non_exhaustive] |
| 84 | pub enum NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule# { |
| 85 | /// Fixed name to comply to rules. Ex. `get_mut_structure` -> `structure_mut`. |
| 86 | Fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Fixed#, |
| 87 | /// Regular rule: removal of the prefix or replacement with `is`. |
| 88 | Regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Regular#, |
| 89 | /// No prefix for `bool` getter. Ex. `get_has_entry` -> `has_entry`. |
| 90 | NoPrefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#NoPrefix#, |
| 91 | /// Applied substitution. Ex. `get_mute` -> `is_muted`. |
| 92 | Substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Substituted#, |
| 93 | } |
| 94 | |
| 95 | impl NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule# { |
| 96 | /// Returns whether renaming required fixing the name to comply with rules. |
| 97 | /// |
| 98 | /// Ex. `get_mut_structure` -> `structure_mut`. |
| 99 | pub fn is_fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_fixed().(&self) -> bool { |
| 100 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#::Fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Fixed#) |
| 101 | } |
| 102 | |
| 103 | /// Returns whether renaming required substituing (part) of the name. |
| 104 | /// |
| 105 | /// Ex. `get_mute` -> `is_muted`. |
| 106 | pub fn is_substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_substituted().(&self) -> bool { |
| 107 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#::Substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Substituted#) |
| 108 | } |
| 109 | |
| 110 | /// Returns whether renaming used the regular strategy. |
| 111 | /// |
| 112 | /// Ex.: |
| 113 | /// * `get_name` -> `name`. |
| 114 | /// * `get_active` -> `is_active`. |
| 115 | pub fn is_regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_regular().(&self) -> bool { |
| 116 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#::Regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Regular#) |
| 117 | } |
| 118 | |
| 119 | /// Returns whether renaming didn't use the `is` prefix for `bool` getter. |
| 120 | /// |
| 121 | /// Ex.: |
| 122 | /// * `get_has_entry` -> `has_entry`. |
| 123 | pub fn is_no_prefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule]is_no_prefix().(&self) -> bool { |
| 124 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#::NoPrefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#NoPrefix#) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule# { |
| 129 | fn fmtrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[NewNameRule][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 130 | use NewNameRulerust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#::*; |
| 131 | match self { |
| 132 | Fixedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Fixed# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("fixed as"), |
| 133 | Substitutedrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Substituted# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("substituted with"), |
| 134 | NoPrefixrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#NoPrefix# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("kept as"), |
| 135 | Regularrust-analyzer cargo fix-getters-rules 0.3.2 new_name/NewNameRule#Regular# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("renamed as"), |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /// Indicates current knowledge about the getter returning exaclty one `bool`. |
| 141 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 142 | pub enum ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool# { |
| 143 | Truerust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#True#, |
| 144 | Falserust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#False#, |
| 145 | Mayberust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#Maybe#, |
| 146 | } |
| 147 | |
| 148 | impl ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool# { |
| 149 | pub fn is_truerust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool]is_true().(&self) -> bool { |
| 150 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::Truerust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#True#) |
| 151 | } |
| 152 | |
| 153 | pub fn is_falserust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool]is_false().(&self) -> bool { |
| 154 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::Falserust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#False#) |
| 155 | } |
| 156 | |
| 157 | pub fn is_mayberust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool]is_maybe().(&self) -> bool { |
| 158 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::Mayberust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#Maybe#) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<bool> for ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool# { |
| 163 | fn fromrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool][`From<bool>`]from().(returns_bool: bool) -> Selfrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool][`From<bool>`] { |
| 164 | if returns_bool { |
| 165 | ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::Truerust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#True# |
| 166 | } else { |
| 167 | ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::Falserust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#False# |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool# { |
| 173 | fn fmtrust-analyzer cargo fix-getters-rules 0.3.2 new_name/impl#[ReturnsBool][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 174 | use ReturnsBoolrust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#::*; |
| 175 | match self { |
| 176 | Falserust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#False# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 177 | Truerust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#True# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("-> bool "), |
| 178 | Mayberust-analyzer cargo fix-getters-rules 0.3.2 new_name/ReturnsBool#Maybe# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("-> ? "), |
| 179 | } |
| 180 | } |
| 181 | } |