From e26e3b05cb0514687f37d6d9e10b0605d0924b5c Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 6 Jan 2023 15:52:45 +0100 Subject: [PATCH] kanji_info example: simplify using .inspect() --- examples/kanji_info.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/examples/kanji_info.rs b/examples/kanji_info.rs index 7566a79..7114de1 100644 --- a/examples/kanji_info.rs +++ b/examples/kanji_info.rs @@ -6,28 +6,24 @@ fn main() { let input = "一日"; let count = jmdict::entries() - .filter(|e| { - if e.kanji_elements().any(|k| k.text == input) { - // note two entries have identical Kanji - // yet differ in reading - println!("--- entry #{} ---", e.number); - for kanji in e.kanji_elements() { - println!("kanji element: {}", kanji.text); - println!(" priority: {:?}\n", kanji.priority); - } + .filter(|e| e.kanji_elements().any(|k| k.text == input)) + .inspect(|e| { + // note two entries have identical Kanji + // yet differ in reading + println!("--- entry #{} ---", e.number); + for kanji in e.kanji_elements() { + println!("kanji element: {}", kanji.text); + println!(" priority: {:?}\n", kanji.priority); + } - for reading in e.reading_elements() { - println!("reading_form: {}", reading.text); - println!(" priority: {:?}\n", reading.priority); + for reading in e.reading_elements() { + println!("reading_form: {}", reading.text); + println!(" priority: {:?}\n", reading.priority); - for info in reading.infos() { - println!("info: {:?}", info); - } + for info in reading.infos() { + println!("info: {:?}", info); } - - return true } - false }) .count(); println!("{} entries for {}", count, input);