diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 342ca3be..579ee594 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -49,6 +49,16 @@ impl<'de> Deserialize<'de> for () { } } +#[cfg(feature = "unstable")] +impl<'de> Deserialize<'de> for ! { + fn deserialize(_deserializer: D) -> Result + where + D: Deserializer<'de>, + { + Err(Error::custom("cannot deserialize `!`")) + } +} + //////////////////////////////////////////////////////////////////////////////// struct BoolVisitor; diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 10427156..ec1ed5e8 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -98,6 +98,7 @@ //! - PathBuf //! - Range\ //! - num::NonZero* +//! - `!` *(unstable)* //! - **Net types**: //! - IpAddr //! - Ipv4Addr diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 9c1535a3..148e1ac4 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -89,7 +89,7 @@ // discussion of these features please refer to this issue: // // https://github.com/serde-rs/serde/issues/812 -#![cfg_attr(feature = "unstable", feature(specialization))] +#![cfg_attr(feature = "unstable", feature(specialization, never_type))] #![cfg_attr(feature = "alloc", feature(alloc))] #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] // Whitelisted clippy lints diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index be07d061..3a4a4efe 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -247,6 +247,16 @@ impl Serialize for () { } } +#[cfg(feature = "unstable")] +impl Serialize for ! { + fn serialize(&self, _serializer: S) -> Result + where + S: Serializer, + { + *self + } +} + //////////////////////////////////////////////////////////////////////////////// macro_rules! tuple_impls { diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index c5c9c423..d1d4bd7f 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -93,6 +93,7 @@ //! - PathBuf //! - Range\ //! - num::NonZero* +//! - `!` *(unstable)* //! - **Net types**: //! - IpAddr //! - Ipv4Addr