Skip to content

Commit d65fa79

Browse files
author
Ed Page
committed
refactor(dict): Make feature flag paths clearer
1 parent e6c595c commit d65fa79

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/dict.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ impl BuiltIn {
4848
.for_each(|mut s| case_correct(&mut s, word_token.case()));
4949
Some(corrections)
5050
}
51+
}
5152

52-
#[cfg(feature = "dict")]
53+
#[cfg(feature = "dict")]
54+
impl BuiltIn {
5355
// Not using `Status` to avoid the allocations
5456
fn correct_with_dict(&self, word: &str) -> Option<&'static [&'static str]> {
5557
if typos_dict::WORD_RANGE.contains(&word.len()) {
@@ -58,13 +60,17 @@ impl BuiltIn {
5860
None
5961
}
6062
}
63+
}
6164

62-
#[cfg(not(feature = "dict"))]
65+
#[cfg(not(feature = "dict"))]
66+
impl BuiltIn {
6367
fn correct_with_dict(&self, _word: &str) -> Option<&'static [&'static str]> {
6468
None
6569
}
70+
}
6671

67-
#[cfg(feature = "vars")]
72+
#[cfg(feature = "vars")]
73+
impl BuiltIn {
6874
fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> {
6975
let mut chained: Vec<_> = corrections
7076
.iter()
@@ -84,12 +90,6 @@ impl BuiltIn {
8490
Status::Corrections(chained)
8591
}
8692

87-
#[cfg(not(feature = "vars"))]
88-
fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> {
89-
Status::Corrections(corrections.iter().map(|c| Cow::Borrowed(*c)).collect())
90-
}
91-
92-
#[cfg(feature = "vars")]
9393
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
9494
if typos_vars::WORD_RANGE.contains(&word.len()) {
9595
map_lookup(&typos_vars::VARS_DICTIONARY, word)
@@ -99,12 +99,6 @@ impl BuiltIn {
9999
}
100100
}
101101

102-
#[cfg(not(feature = "vars"))]
103-
fn correct_with_vars(&self, _word: &str) -> Option<Status<'static>> {
104-
None
105-
}
106-
107-
#[cfg(feature = "vars")]
108102
fn select_variant(
109103
&self,
110104
vars: &'static [(u8, &'static typos_vars::VariantsMap)],
@@ -148,6 +142,17 @@ impl BuiltIn {
148142
}
149143
}
150144

145+
#[cfg(not(feature = "vars"))]
146+
impl BuiltIn {
147+
fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> {
148+
Status::Corrections(corrections.iter().map(|c| Cow::Borrowed(*c)).collect())
149+
}
150+
151+
fn correct_with_vars(&self, _word: &str) -> Option<Status<'static>> {
152+
None
153+
}
154+
}
155+
151156
impl typos::Dictionary for BuiltIn {
152157
fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option<Status<'s>> {
153158
BuiltIn::correct_ident(self, ident)

0 commit comments

Comments
 (0)