iterator/
iterator.rs

1use futures::StreamExt;
2use mysql_slowlog_parser::{EntryCodec, EntrySqlType};
3use std::collections::HashMap;
4use tokio::fs::File;
5use tokio_util::codec::FramedRead;
6
7#[tokio::main]
8async fn main() {
9    let fr = FramedRead::new(
10        File::open("assets/slow-test-queries.log").await.unwrap(),
11        EntryCodec::default(),
12    );
13
14    let future = fr.fold(HashMap::new(), |mut acc, re| async move {
15        let entry = re.unwrap();
16
17        match entry.sql_attributes.sql_type() {
18            Some(st) => {
19                acc.insert(st, acc.get(&st).unwrap_or(&0) + 1);
20            }
21            None => {
22                acc.insert(
23                    EntrySqlType::Unknown,
24                    acc.get(&EntrySqlType::Unknown).unwrap_or(&0) + 1,
25                );
26            }
27        }
28
29        acc
30    });
31
32    let type_counts = future.await;
33
34    for (k, v) in type_counts {
35        println!("{}: {}", k, v);
36    }
37}