[][src]Function text_analysis::count_words

pub fn count_words(words: &Vec<String>) -> Result<HashMap<String, u32>>

Count words included in given &Vec. Returns result as HashMap with <Word as String, Count as u32>. Returns result.

Example

use text_analysis::count_words;
use std::collections::HashMap;
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).unwrap();
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);