From d65fa79d0e449ccef225d54893f26f9af9395b29 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 18 May 2021 19:44:50 -0500 Subject: [PATCH] refactor(dict): Make feature flag paths clearer --- src/dict.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/dict.rs b/src/dict.rs index 52f6bda..5541f5d 100644 --- a/src/dict.rs +++ b/src/dict.rs @@ -48,8 +48,10 @@ impl BuiltIn { .for_each(|mut s| case_correct(&mut s, word_token.case())); Some(corrections) } +} - #[cfg(feature = "dict")] +#[cfg(feature = "dict")] +impl BuiltIn { // Not using `Status` to avoid the allocations fn correct_with_dict(&self, word: &str) -> Option<&'static [&'static str]> { if typos_dict::WORD_RANGE.contains(&word.len()) { @@ -58,13 +60,17 @@ impl BuiltIn { None } } +} - #[cfg(not(feature = "dict"))] +#[cfg(not(feature = "dict"))] +impl BuiltIn { fn correct_with_dict(&self, _word: &str) -> Option<&'static [&'static str]> { None } +} - #[cfg(feature = "vars")] +#[cfg(feature = "vars")] +impl BuiltIn { fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> { let mut chained: Vec<_> = corrections .iter() @@ -84,12 +90,6 @@ impl BuiltIn { Status::Corrections(chained) } - #[cfg(not(feature = "vars"))] - fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> { - Status::Corrections(corrections.iter().map(|c| Cow::Borrowed(*c)).collect()) - } - - #[cfg(feature = "vars")] fn correct_with_vars(&self, word: &str) -> Option> { if typos_vars::WORD_RANGE.contains(&word.len()) { map_lookup(&typos_vars::VARS_DICTIONARY, word) @@ -99,12 +99,6 @@ impl BuiltIn { } } - #[cfg(not(feature = "vars"))] - fn correct_with_vars(&self, _word: &str) -> Option> { - None - } - - #[cfg(feature = "vars")] fn select_variant( &self, vars: &'static [(u8, &'static typos_vars::VariantsMap)], @@ -148,6 +142,17 @@ impl BuiltIn { } } +#[cfg(not(feature = "vars"))] +impl BuiltIn { + fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> { + Status::Corrections(corrections.iter().map(|c| Cow::Borrowed(*c)).collect()) + } + + fn correct_with_vars(&self, _word: &str) -> Option> { + None + } +} + impl typos::Dictionary for BuiltIn { fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option> { BuiltIn::correct_ident(self, ident)