Function parse_string

Source
pub fn parse_string(
    s: &str,
    options: Option<ParseStringOptions>,
) -> Result<Vec<Message>, String>
Examples found in repository?
examples/main.rs (line 10)
6fn main() {
7    let args: Vec<String> = env::args().collect();
8    let file_path = &args[1];
9    let content = fs::read_to_string(file_path).expect("Something went wrong reading the file");
10    let messages = parse_string(&content, None).unwrap();
11
12    let mut user_counts = HashMap::new();
13    for message in messages {
14        if let Some(author) = message.author {
15            *user_counts.entry(author).or_insert(0) += 1;
16        }
17    }
18
19    let mut sorted_users: Vec<_> = user_counts.into_iter().collect();
20    sorted_users.sort_by(|a, b| b.1.cmp(&a.1));
21
22    println!("Users by message count:");
23    for (user, count) in sorted_users {
24        println!("{}: {}", user, count);
25    }
26}