Struct auto_correct_n_suggest::Dictionary[][src]

pub struct Dictionary { /* fields omitted */ }
Expand description

This dictionary will hold all the words/keywords you want to use within your program.

Implementations

impl Dictionary[src]

pub fn new() -> Dictionary[src]

Returns a new dictionary just like the default method The dictionary will always be empty at first, but you can add words to it using the insert method

Examples

use auto_correct_n_suggest;
let mut dictionary = auto_correct_n_suggest::Dictionary::new();

pub fn insert(&mut self, word: String)[src]

Adds a new word to the dictionary Provide a Word String to an existing dictionary to add it the dictionary

Arguments

  • word - The string to be inserted to the dictionary

Examples

use auto_correct_n_suggest;
let mut dictionary = auto_correct_n_suggest::Dictionary::new();
let new_coin = format!("{}", "Dogecoin");
dictionary.insert(new_coin);

pub fn find_words_based_on_prefix(
    &mut self,
    prefix: String
) -> Option<Vec<String>>
[src]

This method helps you get the complete words available based on the prefix provided

Arguments

  • prefix - A string which represents the prefix of words in the dictionary

It returns None if there are no suffixes of the prefix provided

Examples

use auto_correct_n_suggest;
let mut dictionary = auto_correct_n_suggest::Dictionary::new();
let word1 = "Dog".to_string();
dictionary.insert(word1);
let words_available = dictionary
    .find_words_based_on_prefix("Dog".to_string())
    .expect("Words should be present");
assert!(words_available.contains(&"Dog".to_string()));

pub fn auto_suggest_alternative_words(
    &mut self,
    typo: String
) -> Option<Vec<String>>
[src]

This method helps you get alternative words based in your dictionary that are similar to the provided word

Arguments

  • typo - The mistyped word

It returns None if no word in the dictionary matches any sequence of characters of the word given.

Examples

use auto_correct_n_suggest;
let mut dictionary = auto_correct_n_suggest::Dictionary::new();
let word1 = "Dog".to_string();
let word2 = "Dogecoin".to_string();

dictionary.insert(word1);
dictionary.insert(word2);

let words_available = dictionary
    .auto_suggest_alternative_words("Dogecoins".to_string())
    .expect("Suggestions should be available");

assert_eq!(vec!["Dogecoin".to_string()], words_available);
// In this dictionary there's Cats so there isnt any alternative word for Cat
let words_available = dictionary.auto_suggest_alternative_words("Cat".to_string());
assert_eq!(words_available, None);

Trait Implementations

impl Default for Dictionary[src]

fn default() -> Self[src]

Returns a new dictionary which will always be empty

Examples

use auto_correct_n_suggest;
let dictionary = auto_correct_n_suggest::Dictionary::default();

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.