Consistently avoid '?' throughout serde crate

This makes it easy to redefine a 'try' macro to compare compile-time
between `$expr?` and `match $expr { Ok=>v, Err=>return }`.
This commit is contained in:
David Tolnay 2022-09-21 21:33:24 -07:00
parent d208762c81
commit a9320db6f9
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 11 additions and 10 deletions

View File

@ -228,7 +228,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
where
A: EnumAccess<'de>,
{
data.variant::<IgnoredAny>()?.1.newtype_variant()
try!(data.variant::<IgnoredAny>()).1.newtype_variant()
}
}

View File

@ -2268,14 +2268,14 @@ where
where
D: Deserializer<'de>,
{
let (start, end) = deserializer.deserialize_struct(
let (start, end) = try!(deserializer.deserialize_struct(
"Range",
range::FIELDS,
range::RangeVisitor {
expecting: "struct Range",
phantom: PhantomData,
},
)?;
));
Ok(start..end)
}
}
@ -2289,14 +2289,14 @@ where
where
D: Deserializer<'de>,
{
let (start, end) = deserializer.deserialize_struct(
let (start, end) = try!(deserializer.deserialize_struct(
"RangeInclusive",
range::FIELDS,
range::RangeVisitor {
expecting: "struct RangeInclusive",
phantom: PhantomData,
},
)?;
));
Ok(RangeInclusive::new(start, end))
}
}

View File

@ -565,7 +565,7 @@ pub trait Deserialize<'de>: Sized {
D: Deserializer<'de>,
{
// Default implementation just delegates to `deserialize` impl.
*place = Deserialize::deserialize(deserializer)?;
*place = try!(Deserialize::deserialize(deserializer));
Ok(())
}
}

View File

@ -1501,7 +1501,7 @@ where
where
T: de::DeserializeSeed<'de>,
{
match self.map.next_key_seed(seed)? {
match try!(self.map.next_key_seed(seed)) {
Some(key) => Ok((key, private::map_as_enum(self.map))),
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
}

View File

@ -614,9 +614,10 @@ impl Serialize for SystemTime {
S: Serializer,
{
use super::SerializeStruct;
let duration_since_epoch = self
.duration_since(UNIX_EPOCH)
.map_err(|_| S::Error::custom("SystemTime must be later than UNIX_EPOCH"))?;
let duration_since_epoch = match self.duration_since(UNIX_EPOCH) {
Ok(duration_since_epoch) => duration_since_epoch,
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
};
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));