Skip to content

Commit 49603a2

Browse files
committed
Add an example to load dictionaries by path
1 parent 79ed7e8 commit 49603a2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/load-dictionary.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::{fs, io, time::Instant};
2+
3+
use spellbook::Dictionary;
4+
5+
macro_rules! usage {
6+
() => {
7+
eprintln!("Usage: load-dictionary path/to/dict.aff path/to/dict.dic");
8+
eprintln!(" Note: some shells accept a syntax like path/to/dict.{{aff,dic}}");
9+
std::process::exit(1);
10+
};
11+
}
12+
13+
fn main() -> io::Result<()> {
14+
let mut args = std::env::args().skip(1);
15+
let Some(aff) = args.next() else {
16+
usage!();
17+
};
18+
let Some(dic) = args.next() else {
19+
usage!();
20+
};
21+
let aff = fs::read_to_string(aff)?;
22+
let dic = fs::read_to_string(dic)?;
23+
let now = Instant::now();
24+
match Dictionary::new(&aff, &dic) {
25+
Ok(_) => println!("Compiled the dictionary in {:?}", now.elapsed()),
26+
Err(err) => eprintln!("Failed to compile the dictionary: {err}"),
27+
}
28+
Ok(())
29+
}

0 commit comments

Comments
 (0)