Skip to content

Commit

Permalink
Inline de::from_trait into deserialize_numeric_key
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 11, 2023
1 parent 98c4db1 commit f1a28a3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,12 +1126,17 @@ macro_rules! deserialize_numeric_key {
where
V: Visitor<'de>,
{
let parsed = crate::from_str(&self.key);
match (parsed, self.key) {
(Ok(integer), _) => visitor.$visit(integer),
(Err(_), Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
let mut de = crate::Deserializer::from_str(&self.key);
let parsed = Deserialize::deserialize(&mut de);
if let Ok(integer) = parsed {
if de.end().is_ok() {
return visitor.$visit(integer);
}
}
match self.key {
Cow::Borrowed(s) => visitor.visit_borrowed_str(s),
#[cfg(any(feature = "std", feature = "alloc"))]
(Err(_), Cow::Owned(s)) => visitor.visit_string(s),
Cow::Owned(s) => visitor.visit_string(s),
}
}
};
Expand Down

0 comments on commit f1a28a3

Please sign in to comment.