Expand description
cedict is a Rust crate for reading and writing the CC-CEDICT Chinese-English dictionary format. It can be used to implement Chinese dictionaries in Rust. It can also serve as a tool for automating maintenance to the CEDICT project.
§Examples
let line = "你好 你好 [ni3 hao3] /Hello!/Hi!/How are you?/";
let parsed = cedict::parse_line(line);
if let cedict::Line::Entry(entry) = parsed {
assert_eq!(entry.simplified(), "你好");
assert_eq!(entry.pinyin(), "ni3 hao3");
assert_eq!(entry.definitions().collect::<Vec<_>>(), vec!["Hello!", "Hi!", "How are you?"]);
}
use std::fs::File;
match File::open("cedict.txt") {
Ok(file) => {
for word in cedict::parse_reader(file) {
if word.definitions().next().unwrap().contains("Hello") {
println!("{}", word.simplified());
}
}
},
Err(_) => {
println!("Cannot read file");
}
}
Structs§
- Represents a single dictionary entry in the CC-CEDICT format.
Enums§
Functions§
- Check if a line is a comment. Comments start with a ‘#’.
- Check if a line contains metadata. Metadata lines start with ‘#!’.