mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 23:35:26 +00:00
commit
bd366f675e
@ -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;
|
struct BoolVisitor;
|
||||||
|
@ -98,6 +98,7 @@
|
|||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
//! - IpAddr
|
//! - IpAddr
|
||||||
//! - Ipv4Addr
|
//! - Ipv4Addr
|
||||||
|
@ -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 {
|
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"]
|
||||||
|
@ -89,7 +89,7 @@
|
|||||||
// discussion of these features please refer to this issue:
|
// discussion of these features please refer to this issue:
|
||||||
//
|
//
|
||||||
// https://github.com/serde-rs/serde/issues/812
|
// 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 = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
|
@ -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 {
|
macro_rules! tuple_impls {
|
||||||
|
@ -93,6 +93,7 @@
|
|||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
//! - IpAddr
|
//! - IpAddr
|
||||||
//! - Ipv4Addr
|
//! - Ipv4Addr
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(decimal_literal_representation))]
|
#![cfg_attr(feature = "cargo-clippy", allow(decimal_literal_representation))]
|
||||||
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
@ -984,6 +985,16 @@ declare_tests! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
declare_tests! {
|
||||||
|
test_never_result {
|
||||||
|
Ok::<u8, !>(0) => &[
|
||||||
|
Token::NewtypeVariant { name: "Result", variant: "Ok" },
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_osstring() {
|
fn test_osstring() {
|
||||||
@ -1051,6 +1062,20 @@ fn test_cstr_internal_null_end() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[test]
|
||||||
|
fn test_never_type() {
|
||||||
|
assert_de_tokens_error::<!>(&[], "cannot deserialize `!`");
|
||||||
|
|
||||||
|
assert_de_tokens_error::<Result<u8, !>>(
|
||||||
|
&[Token::NewtypeVariant {
|
||||||
|
name: "Result",
|
||||||
|
variant: "Err",
|
||||||
|
}],
|
||||||
|
"cannot deserialize `!`",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
declare_error_tests! {
|
declare_error_tests! {
|
||||||
test_unknown_field<StructDenyUnknown> {
|
test_unknown_field<StructDenyUnknown> {
|
||||||
&[
|
&[
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
@ -548,6 +550,16 @@ declare_tests! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
declare_tests! {
|
||||||
|
test_never_result {
|
||||||
|
Ok::<u8, !>(0) => &[
|
||||||
|
Token::NewtypeVariant { name: "Result", variant: "Ok" },
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_cannot_serialize_paths() {
|
fn test_cannot_serialize_paths() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user