Skip to content

Commit

Permalink
Touch up PR 1948
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 12, 2021
1 parent 99d9151 commit 391d3ab
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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;
Expand Down Expand Up @@ -2537,14 +2536,19 @@ atomic_impl! {
AtomicI64 AtomicU64
}


#[cfg(feature = "std")]
struct FromStrVisitor<T>(&'static str, PhantomData<T>);
struct FromStrVisitor<T> {
expecting: &'static str,
ty: PhantomData<T>,
}

#[cfg(feature = "std")]
impl<T> FromStrVisitor<T> {
fn new(msg: &'static str) -> Self {
FromStrVisitor(msg, PhantomData)
fn new(expecting: &'static str) -> Self {
FromStrVisitor {
expecting: expecting,
ty: PhantomData,
}
}
}

Expand All @@ -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<E>(self, s: &str) -> Result<Self::Value, E>
Expand Down

0 comments on commit 391d3ab

Please sign in to comment.