refactor(dict): Split out a trait

This commit is contained in:
Ed Page committed 2019-07-27 19:50:36 -06:00
1 parent 834b9f77f2
commit adcbe68621
4 files changed
+36 -14

No files matched your search

+26 -4
View File
@@ -4,12 +4,21 @@ use unicase::UniCase;
use crate::tokens::Case;
#[derive(Default)]
pub struct Dictionary {}
pub trait Dictionary {
fn correct_ident<'s, 'w>(
&'s self,
_ident: crate::tokens::Identifier<'w>,
) -> Option<Cow<'s, str>>;
impl Dictionary {
fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Option<Cow<'s, str>>;
}
#[derive(Default)]
pub struct BuiltIn {}
impl BuiltIn {
pub fn new() -> Self {
Dictionary {}
Self {}
}
pub fn correct_ident<'s, 'w>(
@@ -25,6 +34,19 @@ impl Dictionary {
}
}
impl Dictionary for BuiltIn {
fn correct_ident<'s, 'w>(
&'s self,
ident: crate::tokens::Identifier<'w>,
) -> Option<Cow<'s, str>> {
BuiltIn::correct_ident(self, ident)
}
fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Option<Cow<'s, str>> {
BuiltIn::correct_word(self, word)
}
}
fn map_lookup(
map: &'static phf::Map<UniCase<&'static str>, &'static str>,
key: &str,
+1 -1
View File
@@ -260,7 +260,7 @@ fn run() -> Result<i32, failure::Error> {
let ignore_hex = options.ignore_hex().unwrap_or(true);
let binary = options.binary().unwrap_or(false);
let dictionary = typos::Dictionary::new();
let dictionary = typos::BuiltIn::new();
let parser = typos::tokens::ParserBuilder::new()
.ignore_hex(ignore_hex)