harper_core/spell/
dictionary.rs1use blanket::blanket;
2use std::borrow::Cow;
3
4use super::FuzzyMatchResult;
5use super::WordId;
6use crate::DictWordMetadata;
7
8#[blanket(derive(Arc, Ref))]
12pub trait Dictionary: Send + Sync {
13 fn contains_word(&self, word: &[char]) -> bool;
15 fn contains_word_str(&self, word: &str) -> bool;
17 fn contains_exact_word(&self, word: &[char]) -> bool;
19 fn contains_exact_word_str(&self, word: &str) -> bool;
21 fn fuzzy_match(
23 &'_ self,
24 word: &[char],
25 max_distance: u8,
26 max_results: usize,
27 ) -> Vec<FuzzyMatchResult<'_>>;
28 fn fuzzy_match_str(
30 &'_ self,
31 word: &str,
32 max_distance: u8,
33 max_results: usize,
34 ) -> Vec<FuzzyMatchResult<'_>>;
35 fn get_correct_capitalization_of(&self, word: &[char]) -> Option<&'_ [char]>;
36 fn get_word_metadata(&self, word: &[char]) -> Option<Cow<'_, DictWordMetadata>>;
38 fn get_word_metadata_str(&self, word: &str) -> Option<Cow<'_, DictWordMetadata>>;
42
43 fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_>;
45
46 fn word_count(&self) -> usize;
48
49 fn get_word_from_id(&self, id: &WordId) -> Option<&[char]>;
51
52 fn find_words_with_prefix(&self, prefix: &[char]) -> Vec<Cow<'_, [char]>>;
54
55 fn find_words_with_common_prefix(&self, word: &[char]) -> Vec<Cow<'_, [char]>>;
57}