kanji_info example: simplify using .inspect()

main
Stefan Majewsky 2 years ago
parent a709995cef
commit e26e3b05cb

@ -6,28 +6,24 @@
fn main() { fn main() {
let input = "一日"; let input = "一日";
let count = jmdict::entries() let count = jmdict::entries()
.filter(|e| { .filter(|e| e.kanji_elements().any(|k| k.text == input))
if e.kanji_elements().any(|k| k.text == input) { .inspect(|e| {
// note two entries have identical Kanji // note two entries have identical Kanji
// yet differ in reading // yet differ in reading
println!("--- entry #{} ---", e.number); println!("--- entry #{} ---", e.number);
for kanji in e.kanji_elements() { for kanji in e.kanji_elements() {
println!("kanji element: {}", kanji.text); println!("kanji element: {}", kanji.text);
println!(" priority: {:?}\n", kanji.priority); println!(" priority: {:?}\n", kanji.priority);
} }
for reading in e.reading_elements() { for reading in e.reading_elements() {
println!("reading_form: {}", reading.text); println!("reading_form: {}", reading.text);
println!(" priority: {:?}\n", reading.priority); println!(" priority: {:?}\n", reading.priority);
for info in reading.infos() { for info in reading.infos() {
println!("info: {:?}", info); println!("info: {:?}", info);
}
} }
return true
} }
false
}) })
.count(); .count();
println!("{} entries for {}", count, input); println!("{} entries for {}", count, input);

Loading…
Cancel
Save