From 391d3ababf5e329777571c8fe03117d8bbba8d40 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 12 Jan 2021 13:02:53 -0800 Subject: [PATCH] Touch up PR 1948 --- serde/src/de/impls.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index d507de6b9..66c146598 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -1260,7 +1260,7 @@ macro_rules! parse_ip_impl { D: Deserializer<'de>, { if deserializer.is_human_readable() { - deserializer.deserialize_str(FromStrVisitor::<$ty>::new($expecting)) + deserializer.deserialize_str(FromStrVisitor::new($expecting)) } else { <[u8; $size]>::deserialize(deserializer).map(<$ty>::from) } @@ -1415,7 +1415,7 @@ macro_rules! parse_socket_impl { D: Deserializer<'de>, { if deserializer.is_human_readable() { - deserializer.deserialize_str(FromStrVisitor::<$ty>::new($expecting)) + deserializer.deserialize_str(FromStrVisitor::new($expecting)) } else { <(_, u16)>::deserialize(deserializer).map(|(ip, port)| $new(ip, port)) } @@ -1431,7 +1431,6 @@ impl<'de> Deserialize<'de> for net::SocketAddr { D: Deserializer<'de>, { if deserializer.is_human_readable() { - deserializer.deserialize_str(FromStrVisitor::new("socket address")) } else { use lib::net::SocketAddr; @@ -2537,14 +2536,19 @@ atomic_impl! { AtomicI64 AtomicU64 } - #[cfg(feature = "std")] -struct FromStrVisitor(&'static str, PhantomData); +struct FromStrVisitor { + expecting: &'static str, + ty: PhantomData, +} #[cfg(feature = "std")] impl FromStrVisitor { - fn new(msg: &'static str) -> Self { - FromStrVisitor(msg, PhantomData) + fn new(expecting: &'static str) -> Self { + FromStrVisitor { + expecting: expecting, + ty: PhantomData, + } } } @@ -2557,7 +2561,7 @@ where type Value = T; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str(self.0) + formatter.write_str(self.expecting) } fn visit_str(self, s: &str) -> Result