Skip to content

Commit 1692c52

Browse files
committed
style: cargo fmt
1 parent 58bd8a9 commit 1692c52

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

example-rust/src/main.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use glob::glob;
22
use itertools::Itertools;
33
use lexical_sort::{natural_lexical_cmp, StringSort};
4+
use once_cell::sync::Lazy;
45
use regex::Regex;
56
use std::path::Path;
67
use tokio::fs;
78
use yaml_rust::YamlLoader;
8-
use once_cell::sync::Lazy;
99

1010
const SORT: bool = false;
1111
const OUTDIR: &str = "words_new";
@@ -36,50 +36,49 @@ async fn get_filename_from_meta(path: &Path) -> anyhow::Result<String> {
3636
let docs = YamlLoader::load_from_str(&yaml)?;
3737
let meta = &docs[0];
3838

39-
let label = meta["label"].as_str().ok_or_else(|| anyhow::anyhow!("label not found"))?;
39+
let label = meta["label"]
40+
.as_str()
41+
.ok_or_else(|| anyhow::anyhow!("label not found"))?;
4042

41-
Ok(format!(
42-
"{}/extracted-words-for-{}.txt",
43-
OUTDIR,
44-
label
45-
))
43+
Ok(format!("{}/extracted-words-for-{}.txt", OUTDIR, label))
4644
}
4745

4846
#[tokio::main]
4947
async fn main() -> std::io::Result<()> {
5048
let start = std::time::Instant::now();
5149
let path = glob(FILE_DIR).expect("failed to read glob pattern");
5250

53-
let submissions = path
54-
.map(|entry| async {
55-
let yaml_path = entry.expect("should be existed");
56-
let txt_path = yaml_path.with_extension("txt");
57-
58-
let outdir_submission = async {
59-
create_outdir().await.expect("unable to create outdir")
60-
};
61-
62-
let read_text_file_submission = async {
63-
let data = read_file(&txt_path).await;
64-
let tokens = get_unique_token(&data);
65-
66-
tokens.join("\n")
67-
};
68-
69-
let filename_submission = async {
70-
get_filename_from_meta(&yaml_path)
71-
.await
72-
.expect("should be existed")
73-
};
74-
75-
let (tokens, filename, _) = tokio::join!(read_text_file_submission, filename_submission, outdir_submission,);
76-
fs::write(filename, tokens).await.expect("failed to write");
77-
});
51+
let submissions = path.map(|entry| async {
52+
let yaml_path = entry.expect("should be existed");
53+
let txt_path = yaml_path.with_extension("txt");
54+
55+
let outdir_submission = async { create_outdir().await.expect("unable to create outdir") };
56+
57+
let read_text_file_submission = async {
58+
let data = read_file(&txt_path).await;
59+
let tokens = get_unique_token(&data);
60+
61+
tokens.join("\n")
62+
};
63+
64+
let filename_submission = async {
65+
get_filename_from_meta(&yaml_path)
66+
.await
67+
.expect("should be existed")
68+
};
69+
70+
let (tokens, filename, _) = tokio::join!(
71+
read_text_file_submission,
72+
filename_submission,
73+
outdir_submission,
74+
);
75+
fs::write(filename, tokens).await.expect("failed to write");
76+
});
7877

7978
futures::future::join_all(submissions).await;
8079

8180
println!("{:?}", start.elapsed());
8281
Ok(())
8382
}
8483

85-
// 2s
84+
// 2s

0 commit comments

Comments
 (0)