mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-26 11:01:00 -05:00
refactor(dict): Make feature flag paths clearer
This commit is contained in:
parent
e6c595c585
commit
d65fa79d0e
1 changed files with 20 additions and 15 deletions
35
src/dict.rs
35
src/dict.rs
|
@ -48,8 +48,10 @@ impl BuiltIn {
|
||||||
.for_each(|mut s| case_correct(&mut s, word_token.case()));
|
.for_each(|mut s| case_correct(&mut s, word_token.case()));
|
||||||
Some(corrections)
|
Some(corrections)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dict")]
|
#[cfg(feature = "dict")]
|
||||||
|
impl BuiltIn {
|
||||||
// Not using `Status` to avoid the allocations
|
// Not using `Status` to avoid the allocations
|
||||||
fn correct_with_dict(&self, word: &str) -> Option<&'static [&'static str]> {
|
fn correct_with_dict(&self, word: &str) -> Option<&'static [&'static str]> {
|
||||||
if typos_dict::WORD_RANGE.contains(&word.len()) {
|
if typos_dict::WORD_RANGE.contains(&word.len()) {
|
||||||
|
@ -58,13 +60,17 @@ impl BuiltIn {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "dict"))]
|
#[cfg(not(feature = "dict"))]
|
||||||
|
impl BuiltIn {
|
||||||
fn correct_with_dict(&self, _word: &str) -> Option<&'static [&'static str]> {
|
fn correct_with_dict(&self, _word: &str) -> Option<&'static [&'static str]> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "vars")]
|
#[cfg(feature = "vars")]
|
||||||
|
impl BuiltIn {
|
||||||
fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> {
|
fn chain_with_vars(&self, corrections: &'static [&'static str]) -> Status<'static> {
|
||||||
let mut chained: Vec<_> = corrections
|
let mut chained: Vec<_> = corrections
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -84,12 +90,6 @@ impl BuiltIn {
|
||||||
Status::Corrections(chained)
|
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<Status<'static>> {
|
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
|
||||||
if typos_vars::WORD_RANGE.contains(&word.len()) {
|
if typos_vars::WORD_RANGE.contains(&word.len()) {
|
||||||
map_lookup(&typos_vars::VARS_DICTIONARY, word)
|
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<Status<'static>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "vars")]
|
|
||||||
fn select_variant(
|
fn select_variant(
|
||||||
&self,
|
&self,
|
||||||
vars: &'static [(u8, &'static typos_vars::VariantsMap)],
|
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<Status<'static>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl typos::Dictionary for BuiltIn {
|
impl typos::Dictionary for BuiltIn {
|
||||||
fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option<Status<'s>> {
|
fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option<Status<'s>> {
|
||||||
BuiltIn::correct_ident(self, ident)
|
BuiltIn::correct_ident(self, ident)
|
||||||
|
|
Loading…
Reference in a new issue