Stop eagerly checking for missing values

This commit is contained in:
Dirkjan Ochtman 2022-12-02 09:59:25 +01:00
parent 99dab24219
commit a1d7d826f8
1 changed files with 20 additions and 34 deletions

View File

@ -144,14 +144,12 @@ macro_rules! from_xml_for_number {
let mut value = None; let mut value = None;
FromXmlStr::<Self>::deserialize(deserializer, &mut value)?; FromXmlStr::<Self>::deserialize(deserializer, &mut value)?;
match value { if let Some(value) = value {
Some(value) => {
*into = Some(value.0); *into = Some(value.0);
}
Ok(()) Ok(())
} }
None => Err(Error::MissingValue(Kind::Scalar)),
}
}
const KIND: Kind = Kind::Scalar; const KIND: Kind = Kind::Scalar;
} }
@ -190,14 +188,12 @@ impl<'xml> FromXml<'xml> for char {
let mut value = None; let mut value = None;
FromXmlStr::<Self>::deserialize(deserializer, &mut value)?; FromXmlStr::<Self>::deserialize(deserializer, &mut value)?;
match value { if let Some(value) = value {
Some(value) => {
*into = Some(value.0); *into = Some(value.0);
}
Ok(()) Ok(())
} }
None => Err(Error::MissingValue(Kind::Scalar)),
}
}
const KIND: Kind = Kind::Scalar; const KIND: Kind = Kind::Scalar;
} }
@ -283,14 +279,12 @@ where
let mut value = None; let mut value = None;
T::Owned::deserialize(deserializer, &mut value)?; T::Owned::deserialize(deserializer, &mut value)?;
match value { if let Some(value) = value {
Some(value) => {
*into = Some(Cow::Owned(value)); *into = Some(Cow::Owned(value));
}
Ok(()) Ok(())
} }
None => Err(Error::MissingValue(Kind::Scalar)),
}
}
const KIND: Kind = Kind::Scalar; const KIND: Kind = Kind::Scalar;
} }
@ -308,24 +302,18 @@ impl<'xml, T: FromXml<'xml>> FromXml<'xml> for Option<T> {
match into.as_mut() { match into.as_mut() {
Some(value) => { Some(value) => {
<T>::deserialize(deserializer, value)?; <T>::deserialize(deserializer, value)?;
match value {
Some(_) => Ok(()),
None => Err(Error::MissingValue(<T as FromXml<'_>>::KIND)),
}
} }
None => { None => {
let mut value = None; let mut value = None;
<T>::deserialize(deserializer, &mut value)?; <T>::deserialize(deserializer, &mut value)?;
match value { if let Some(value) = value {
Some(value) => {
*into = Some(Some(value)); *into = Some(Some(value));
}
}
}
Ok(()) Ok(())
} }
None => Err(Error::MissingValue(<T as FromXml<'_>>::KIND)),
}
}
}
}
fn missing_value() -> Result<Self, Error> { fn missing_value() -> Result<Self, Error> {
Ok(None) Ok(None)
@ -709,14 +697,12 @@ impl<'xml> FromXml<'xml> for IpAddr {
let mut value = None; let mut value = None;
FromXmlStr::<Self>::deserialize(deserializer, &mut value)?; FromXmlStr::<Self>::deserialize(deserializer, &mut value)?;
match value { if let Some(value) = value {
Some(value) => {
*into = Some(value.0); *into = Some(value.0);
}
Ok(()) Ok(())
} }
None => Err(Error::MissingValue(Kind::Scalar)),
}
}
const KIND: Kind = Kind::Scalar; const KIND: Kind = Kind::Scalar;
} }