Properly deserialize tags if null

This commit is contained in:
Greg Heartsfield 2021-11-21 22:01:34 -06:00
parent d81949c31b
commit 5e75370a67

View File

@ -19,12 +19,13 @@ pub struct Event {
type Tag = Vec<Vec<String>>; type Tag = Vec<Vec<String>>;
// handle a default value (empty vec) for null tags
fn tag_from_string<'de, D>(deserializer: D) -> Result<Tag, D::Error> fn tag_from_string<'de, D>(deserializer: D) -> Result<Tag, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let s: Option<String> = Deserialize::deserialize(deserializer)?; let opt = Option::deserialize(deserializer)?;
Ok(vec![]) Ok(opt.unwrap_or_else(|| vec![]))
} }
fn u32_from_string<'de, D>(deserializer: D) -> Result<u32, D::Error> fn u32_from_string<'de, D>(deserializer: D) -> Result<u32, D::Error>