Function text_analysis::count_words
source · pub fn count_words(words: &[String]) -> HashMap<String, u32>
Expand description
Takes &Vec
§Example
#[test]
fn test_count_words() {
use text_analysiss::count_words;
let words = vec![
"one".to_string(),
"two".to_string(),
"two".to_string(),
"three".to_string(),
"three".to_string(),
"three".to_string(),
];
let counted = count_words(&words);
let mut words_map = HashMap::new();
words_map.insert("one".to_string(), 1 as u32);
words_map.insert("two".to_string(), 2 as u32);
words_map.insert("three".to_string(), 3 as u32);
assert_eq!(counted, words_map);
}