Skip to content

Commit

Permalink
IntoDeserializer for !
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 3, 2018
1 parent 338fb67 commit fd6178c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions serde/src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,48 @@ where

////////////////////////////////////////////////////////////////////////////////

/// A deserializer that cannot be instantiated.
#[cfg(feature = "unstable")]
pub struct NeverDeserializer<E> {
never: !,
marker: PhantomData<E>,
}

#[cfg(feature = "unstable")]
impl<'de, E> IntoDeserializer<'de, E> for !
where
E: de::Error,
{
type Deserializer = NeverDeserializer<E>;

fn into_deserializer(self) -> Self::Deserializer {
self
}
}

#[cfg(feature = "unstable")]
impl<'de, E> de::Deserializer<'de> for NeverDeserializer<E>
where
E: de::Error,
{
type Error = E;

fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
self.never
}

forward_to_deserialize_any! {
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
bytes byte_buf option unit unit_struct newtype_struct seq tuple
tuple_struct map struct enum identifier ignored_any
}
}

////////////////////////////////////////////////////////////////////////////////

macro_rules! primitive_deserializer {
($ty:ty, $doc:tt, $name:ident, $method:ident $($cast:tt)*) => {
#[doc = "A deserializer holding"]
Expand Down

0 comments on commit fd6178c

Please sign in to comment.