|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
use core::panic;
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
@ -42,17 +43,7 @@ impl<'de> Deserialize<'de> for ChallengeWord {
|
|
|
|
|
&"a string or map",
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
let dictionary = map.get("dictionary").and_then(|value| match value {
|
|
|
|
|
Value::Null => None,
|
|
|
|
|
_ => Some(value.as_str().unwrap().to_owned()),
|
|
|
|
|
});
|
|
|
|
|
let pos: Option<PartOfSpeech> = map
|
|
|
|
|
.get("pos")
|
|
|
|
|
.map(|value| value.as_str().unwrap().parse().unwrap());
|
|
|
|
|
Ok(ChallengeWord {
|
|
|
|
|
dictionary,
|
|
|
|
|
pos,
|
|
|
|
|
text: map.get("text").map(|value| match value {
|
|
|
|
|
let text = map.get("text").map(|value| match value {
|
|
|
|
|
Value::String(string) => vec![Furigana {
|
|
|
|
|
kanji: string.clone(),
|
|
|
|
|
furigana: None,
|
|
|
|
@ -75,7 +66,26 @@ impl<'de> Deserialize<'de> for ChallengeWord {
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
});
|
|
|
|
|
let dictionary = match map.get("dictionary") {
|
|
|
|
|
Some(value) => match value {
|
|
|
|
|
Value::Null => None,
|
|
|
|
|
Value::String(dictionary) => Some(if !dictionary.starts_with("http") {
|
|
|
|
|
format!("https://jisho.org/word/{dictionary}")
|
|
|
|
|
} else {
|
|
|
|
|
dictionary.to_owned()
|
|
|
|
|
}),
|
|
|
|
|
_ => panic!("dictionary must be string!"),
|
|
|
|
|
},
|
|
|
|
|
None => text.as_ref().map(|furigana| furigana.iter().map(|segment| segment.kanji.clone()).collect()),
|
|
|
|
|
};
|
|
|
|
|
let pos: Option<PartOfSpeech> = map
|
|
|
|
|
.get("pos")
|
|
|
|
|
.map(|value| value.as_str().unwrap().parse().unwrap());
|
|
|
|
|
Ok(ChallengeWord {
|
|
|
|
|
dictionary,
|
|
|
|
|
pos,
|
|
|
|
|
text,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|