Implement traits for !

This commit is contained in:
David Tolnay 2018-06-03 00:02:29 -07:00
parent 0a71fe329c
commit 338fb67853
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 23 additions and 1 deletions

View File

@ -49,6 +49,16 @@ impl<'de> Deserialize<'de> for () {
}
}
#[cfg(feature = "unstable")]
impl<'de> Deserialize<'de> for ! {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Err(Error::custom("cannot deserialize `!`"))
}
}
////////////////////////////////////////////////////////////////////////////////
struct BoolVisitor;

View File

@ -98,6 +98,7 @@
//! - PathBuf
//! - Range\<T\>
//! - num::NonZero*
//! - `!` *(unstable)*
//! - **Net types**:
//! - IpAddr
//! - Ipv4Addr

View File

@ -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

View File

@ -247,6 +247,16 @@ impl Serialize for () {
}
}
#[cfg(feature = "unstable")]
impl Serialize for ! {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
*self
}
}
////////////////////////////////////////////////////////////////////////////////
macro_rules! tuple_impls {

View File

@ -93,6 +93,7 @@
//! - PathBuf
//! - Range\<T\>
//! - num::NonZero*
//! - `!` *(unstable)*
//! - **Net types**:
//! - IpAddr
//! - Ipv4Addr