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