mirror of
https://github.com/helix-editor/spellbook.git
synced 2025-10-05 15:52:42 +02:00
Add an example to load dictionaries by path
This commit is contained in:
29
examples/load-dictionary.rs
Normal file
29
examples/load-dictionary.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::{fs, io, time::Instant};
|
||||
|
||||
use spellbook::Dictionary;
|
||||
|
||||
macro_rules! usage {
|
||||
() => {
|
||||
eprintln!("Usage: load-dictionary path/to/dict.aff path/to/dict.dic");
|
||||
eprintln!(" Note: some shells accept a syntax like path/to/dict.{{aff,dic}}");
|
||||
std::process::exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let Some(aff) = args.next() else {
|
||||
usage!();
|
||||
};
|
||||
let Some(dic) = args.next() else {
|
||||
usage!();
|
||||
};
|
||||
let aff = fs::read_to_string(aff)?;
|
||||
let dic = fs::read_to_string(dic)?;
|
||||
let now = Instant::now();
|
||||
match Dictionary::new(&aff, &dic) {
|
||||
Ok(_) => println!("Compiled the dictionary in {:?}", now.elapsed()),
|
||||
Err(err) => eprintln!("Failed to compile the dictionary: {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user