address feedback from code review

main
Sarah Allen 2 years ago
parent 4b58333fc2
commit efdecaee2c

@ -2,24 +2,21 @@
* SPDX-License-Identifier: Apache-2.0 Refer to the file "LICENSE" for details. * SPDX-License-Identifier: Apache-2.0 Refer to the file "LICENSE" for details.
* example illustrating how to access kanji and reading information for a word * example illustrating how to access kanji and reading information for a word
*******************************************************************************/ *******************************************************************************/
use jmdict::{KanjiElement, ReadingElement};
fn main() { fn main() {
let input = "一日"; let input = "一日";
let count = jmdict::entries() let count = jmdict::entries()
.filter(|e| { .filter(|e| {
let mut result = false;
if e.kanji_elements().any(|k| k.text == input) { if e.kanji_elements().any(|k| k.text == input) {
result = true; // note two entries have identical Kanji and reading
// yet differ in "sense" not shown in this example
println!("--- entry #{} ---", e.number); println!("--- entry #{} ---", e.number);
let kanji_elements: Vec<KanjiElement> = e.kanji_elements().map(|ke| ke).collect(); for kanji in e.kanji_elements() {
for kanji in &kanji_elements {
println!("kanji element: {}", kanji.text); println!("kanji element: {}", kanji.text);
println!(" priority: {:?}\n", kanji.priority); println!(" priority: {:?}\n", kanji.priority);
} }
let reading_forms: Vec<ReadingElement> = e.reading_elements().map(|item| item).collect(); for reading in e.reading_elements() {
for reading in reading_forms {
println!("reading_form: {}", reading.text); println!("reading_form: {}", reading.text);
println!(" priority: {:?}\n", reading.priority); println!(" priority: {:?}\n", reading.priority);
@ -28,11 +25,9 @@ fn main() {
} }
} }
return true
// let sense = e.senses().next().unwrap().text;
} }
result false
}) })
.count(); .count();
println!("{} entries for {}", count, input); println!("{} entries for {}", count, input);

Loading…
Cancel
Save