Function lib_word_count::count_words [-] [+] [src]

pub fn count_words(input: &str, word_index: &mut Vec<IndexedWord>)

Count the appearances of each word in a string.

Arguments

Examples

let mut word_index = Vec::new();
let input = "I like cookies. Mmm... Cookies.";

lib_word_count::count_words(input, &mut word_index);

assert_eq!(word_index.len(), 4);

assert_eq!(word_index[0].word, "cookies".to_string());
assert_eq!(word_index[1].word, "i".to_string());
assert_eq!(word_index[2].word, "like".to_string());
assert_eq!(word_index[3].word, "mmm".to_string());

assert_eq!(word_index[0].appeared, 2);
assert_eq!(word_index[1].appeared, 1);
assert_eq!(word_index[2].appeared, 1);
assert_eq!(word_index[3].appeared, 1);