Eliminate inferred bound on error type of value deserializer Debug impls

This commit is contained in:
David Tolnay 2021-01-23 22:53:20 -08:00
parent ac4001e590
commit cdc2fa1b9f
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -135,7 +135,6 @@ where
} }
/// A deserializer holding a `()`. /// A deserializer holding a `()`.
#[derive(Debug)]
pub struct UnitDeserializer<E> { pub struct UnitDeserializer<E> {
marker: PhantomData<E>, marker: PhantomData<E>,
} }
@ -169,6 +168,12 @@ where
} }
} }
impl<E> Debug for UnitDeserializer<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.debug_struct("UnitDeserializer").finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer that cannot be instantiated. /// A deserializer that cannot be instantiated.
@ -217,7 +222,6 @@ macro_rules! primitive_deserializer {
($ty:ty, $doc:tt, $name:ident, $method:ident $($cast:tt)*) => { ($ty:ty, $doc:tt, $name:ident, $method:ident $($cast:tt)*) => {
#[doc = "A deserializer holding"] #[doc = "A deserializer holding"]
#[doc = $doc] #[doc = $doc]
#[derive(Debug)]
pub struct $name<E> { pub struct $name<E> {
value: $ty, value: $ty,
marker: PhantomData<E> marker: PhantomData<E>
@ -258,6 +262,15 @@ macro_rules! primitive_deserializer {
visitor.$method(self.value $($cast)*) visitor.$method(self.value $($cast)*)
} }
} }
impl<E> Debug for $name<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct(stringify!($name))
.field("value", &self.value)
.finish()
}
}
} }
} }
@ -281,7 +294,6 @@ serde_if_integer128! {
} }
/// A deserializer holding a `u32`. /// A deserializer holding a `u32`.
#[derive(Debug)]
pub struct U32Deserializer<E> { pub struct U32Deserializer<E> {
value: u32, value: u32,
marker: PhantomData<E>, marker: PhantomData<E>,
@ -352,10 +364,18 @@ where
} }
} }
impl<E> Debug for U32Deserializer<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("U32Deserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer holding a `&str`. /// A deserializer holding a `&str`.
#[derive(Debug)]
pub struct StrDeserializer<'a, E> { pub struct StrDeserializer<'a, E> {
value: &'a str, value: &'a str,
marker: PhantomData<E>, marker: PhantomData<E>,
@ -426,11 +446,19 @@ where
} }
} }
impl<'a, E> Debug for StrDeserializer<'a, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("StrDeserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer holding a `&str` with a lifetime tied to another /// A deserializer holding a `&str` with a lifetime tied to another
/// deserializer. /// deserializer.
#[derive(Debug)]
pub struct BorrowedStrDeserializer<'de, E> { pub struct BorrowedStrDeserializer<'de, E> {
value: &'de str, value: &'de str,
marker: PhantomData<E>, marker: PhantomData<E>,
@ -497,11 +525,19 @@ where
} }
} }
impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("BorrowedStrDeserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer holding a `String`. /// A deserializer holding a `String`.
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug)]
pub struct StringDeserializer<E> { pub struct StringDeserializer<E> {
value: String, value: String,
marker: PhantomData<E>, marker: PhantomData<E>,
@ -583,11 +619,20 @@ where
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))]
impl<E> Debug for StringDeserializer<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("StringDeserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer holding a `Cow<str>`. /// A deserializer holding a `Cow<str>`.
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug)]
pub struct CowStrDeserializer<'a, E> { pub struct CowStrDeserializer<'a, E> {
value: Cow<'a, str>, value: Cow<'a, str>,
marker: PhantomData<E>, marker: PhantomData<E>,
@ -672,10 +717,19 @@ where
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, E> Debug for CowStrDeserializer<'a, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("CowStrDeserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer holding a `&[u8]`. Always calls [`Visitor::visit_bytes`]. /// A deserializer holding a `&[u8]`. Always calls [`Visitor::visit_bytes`].
#[derive(Debug)]
pub struct BytesDeserializer<'a, E> { pub struct BytesDeserializer<'a, E> {
value: &'a [u8], value: &'a [u8],
marker: PhantomData<E>, marker: PhantomData<E>,
@ -724,9 +778,17 @@ where
} }
} }
impl<'a, E> Debug for BytesDeserializer<'a, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("BytesDeserializer")
.field("value", &self.value)
.finish()
}
}
/// A deserializer holding a `&[u8]` with a lifetime tied to another /// A deserializer holding a `&[u8]` with a lifetime tied to another
/// deserializer. Always calls [`Visitor::visit_borrowed_bytes`]. /// deserializer. Always calls [`Visitor::visit_borrowed_bytes`].
#[derive(Debug)]
pub struct BorrowedBytesDeserializer<'de, E> { pub struct BorrowedBytesDeserializer<'de, E> {
value: &'de [u8], value: &'de [u8],
marker: PhantomData<E>, marker: PhantomData<E>,
@ -764,10 +826,19 @@ where
} }
} }
impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("BorrowedBytesDeserializer")
.field("value", &self.value)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A deserializer that iterates over a sequence. /// A deserializer that iterates over a sequence.
#[derive(Clone, Debug)] #[derive(Clone)]
pub struct SeqDeserializer<I, E> { pub struct SeqDeserializer<I, E> {
iter: iter::Fuse<I>, iter: iter::Fuse<I>,
count: usize, count: usize,
@ -872,6 +943,19 @@ impl Expected for ExpectedInSeq {
} }
} }
impl<I, E> Debug for SeqDeserializer<I, E>
where
I: Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("SeqDeserializer")
.field("iter", &self.iter)
.field("count", &self.count)
.finish()
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
@ -1167,7 +1251,6 @@ where
} }
} }
// Cannot #[derive(Debug)] because of the bound `Second<I::Item>: Debug`.
impl<'de, I, E> Debug for MapDeserializer<'de, I, E> impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
where where
I: Iterator + Debug, I: Iterator + Debug,
@ -1180,8 +1263,6 @@ where
.field("iter", &self.iter) .field("iter", &self.iter)
.field("value", &self.value) .field("value", &self.value)
.field("count", &self.count) .field("count", &self.count)
.field("lifetime", &self.lifetime)
.field("error", &self.error)
.finish() .finish()
} }
} }