2017-04-13 19:34:42 -05:00
|
|
|
|
// Copyright 2017 Serde Developer
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
2016-05-07 14:33:59 -05:00
|
|
|
|
// These just test that serde_codegen is able to produce code that compiles
|
2016-05-15 17:54:20 -05:00
|
|
|
|
// successfully when there are a variety of generics and non-(de)serializable
|
|
|
|
|
// types involved.
|
2016-05-07 14:33:59 -05:00
|
|
|
|
|
2017-09-09 13:34:08 -05:00
|
|
|
|
#![deny(warnings)]
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#![cfg_attr(feature = "unstable", feature(non_ascii_idents))]
|
2017-02-24 17:32:13 -06:00
|
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
|
2016-05-07 14:33:59 -05:00
|
|
|
|
extern crate serde;
|
|
|
|
|
use self::serde::ser::{Serialize, Serializer};
|
2017-03-27 00:56:58 -05:00
|
|
|
|
use self::serde::de::{DeserializeOwned, Deserializer};
|
2016-05-07 14:33:59 -05:00
|
|
|
|
|
2016-08-19 10:12:38 -05:00
|
|
|
|
use std::borrow::Cow;
|
2016-07-22 01:22:38 -05:00
|
|
|
|
use std::marker::PhantomData;
|
2017-02-01 11:42:12 -06:00
|
|
|
|
use std::result::Result as StdResult;
|
2016-07-22 01:22:38 -05:00
|
|
|
|
|
2016-09-07 18:25:22 -05:00
|
|
|
|
// Try to trip up the generated code if it fails to use fully qualified paths.
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct Result;
|
2017-02-01 11:42:12 -06:00
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct Ok;
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct Err;
|
2016-09-07 18:25:22 -05:00
|
|
|
|
|
2016-05-07 14:33:59 -05:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_gen() {
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct With<T> {
|
|
|
|
|
t: T,
|
2016-05-15 17:54:20 -05:00
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
x: X,
|
|
|
|
|
}
|
|
|
|
|
assert::<With<i32>>();
|
|
|
|
|
|
2017-02-14 19:36:50 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct WithTogether<T> {
|
|
|
|
|
t: T,
|
|
|
|
|
#[serde(with="both_x")]
|
|
|
|
|
x: X,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithTogether<i32>>();
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct WithRef<'a, T: 'a> {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
t: Option<&'a T>,
|
2016-05-15 17:54:20 -05:00
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
x: X,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithRef<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct PhantomX {
|
|
|
|
|
x: PhantomData<X>,
|
|
|
|
|
}
|
|
|
|
|
assert::<PhantomX>();
|
|
|
|
|
|
2016-07-22 11:05:36 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct PhantomT<T> {
|
|
|
|
|
t: PhantomData<T>,
|
|
|
|
|
}
|
|
|
|
|
assert::<PhantomT<X>>();
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct NoBounds<T> {
|
|
|
|
|
t: T,
|
|
|
|
|
option: Option<T>,
|
|
|
|
|
boxed: Box<T>,
|
|
|
|
|
option_boxed: Option<Box<T>>,
|
|
|
|
|
}
|
|
|
|
|
assert::<NoBounds<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum EnumWith<T> {
|
|
|
|
|
Unit,
|
|
|
|
|
Newtype(
|
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
X
|
|
|
|
|
),
|
2016-07-22 10:49:51 -05:00
|
|
|
|
Tuple(
|
|
|
|
|
T,
|
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
X
|
|
|
|
|
),
|
2016-07-22 10:49:51 -05:00
|
|
|
|
Struct {
|
|
|
|
|
t: T,
|
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
x: X,
|
|
|
|
|
},
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
assert::<EnumWith<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
struct MultipleRef<'a, 'b, 'c, T>
|
|
|
|
|
where
|
|
|
|
|
T: 'c,
|
|
|
|
|
'c: 'b,
|
|
|
|
|
'b: 'a,
|
|
|
|
|
{
|
2016-07-22 10:49:51 -05:00
|
|
|
|
t: T,
|
|
|
|
|
rrrt: &'a &'b &'c T,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<MultipleRef<i32>>();
|
2016-05-07 14:33:59 -05:00
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Newtype(
|
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
|
|
|
|
X
|
|
|
|
|
);
|
|
|
|
|
assert::<Newtype>();
|
2016-05-19 01:46:06 -05:00
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Tuple<T>(
|
|
|
|
|
T,
|
|
|
|
|
#[serde(serialize_with="ser_x", deserialize_with="de_x")]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
X
|
2016-07-22 10:49:51 -05:00
|
|
|
|
);
|
|
|
|
|
assert::<Tuple<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum TreeNode<D> {
|
|
|
|
|
Split {
|
|
|
|
|
left: Box<TreeNode<D>>,
|
|
|
|
|
right: Box<TreeNode<D>>,
|
|
|
|
|
},
|
2017-04-13 14:28:23 -05:00
|
|
|
|
Leaf { data: D },
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
assert::<TreeNode<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct ListNode<D> {
|
2016-05-21 00:03:20 -05:00
|
|
|
|
data: D,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
next: Box<ListNode<D>>,
|
|
|
|
|
}
|
|
|
|
|
assert::<ListNode<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct RecursiveA {
|
|
|
|
|
b: Box<RecursiveB>,
|
|
|
|
|
}
|
|
|
|
|
assert::<RecursiveA>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum RecursiveB {
|
|
|
|
|
A(RecursiveA),
|
|
|
|
|
}
|
|
|
|
|
assert::<RecursiveB>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct RecursiveGenericA<T> {
|
|
|
|
|
t: T,
|
|
|
|
|
b: Box<RecursiveGenericB<T>>,
|
|
|
|
|
}
|
|
|
|
|
assert::<RecursiveGenericA<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum RecursiveGenericB<T> {
|
|
|
|
|
T(T),
|
|
|
|
|
A(RecursiveGenericA<T>),
|
|
|
|
|
}
|
|
|
|
|
assert::<RecursiveGenericB<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
struct OptionStatic<'a> {
|
|
|
|
|
a: Option<&'a str>,
|
|
|
|
|
b: Option<&'static str>,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<OptionStatic>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(bound="D: SerializeWith + DeserializeWith")]
|
|
|
|
|
struct WithTraits1<D, E> {
|
|
|
|
|
#[serde(serialize_with="SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with="DeserializeWith::deserialize_with")]
|
|
|
|
|
d: D,
|
|
|
|
|
#[serde(serialize_with="SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with="DeserializeWith::deserialize_with",
|
|
|
|
|
bound="E: SerializeWith + DeserializeWith")]
|
|
|
|
|
e: E,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithTraits1<X, X>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(bound(serialize="D: SerializeWith",
|
|
|
|
|
deserialize="D: DeserializeWith"))]
|
|
|
|
|
struct WithTraits2<D, E> {
|
|
|
|
|
#[serde(serialize_with="SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with="DeserializeWith::deserialize_with")]
|
|
|
|
|
d: D,
|
|
|
|
|
#[serde(serialize_with="SerializeWith::serialize_with",
|
|
|
|
|
bound(serialize="E: SerializeWith"))]
|
|
|
|
|
#[serde(deserialize_with="DeserializeWith::deserialize_with",
|
|
|
|
|
bound(deserialize="E: DeserializeWith"))]
|
|
|
|
|
e: E,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithTraits2<X, X>>();
|
2016-08-19 10:12:38 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct CowStr<'a>(Cow<'a, str>);
|
|
|
|
|
assert::<CowStr>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-03-27 00:56:58 -05:00
|
|
|
|
#[serde(bound(deserialize = "T::Owned: DeserializeOwned"))]
|
2016-08-19 10:12:38 -05:00
|
|
|
|
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);
|
|
|
|
|
assert::<CowT<str>>();
|
2016-09-02 13:42:26 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct EmptyStruct {}
|
|
|
|
|
assert::<EmptyStruct>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum EmptyEnumVariant {
|
|
|
|
|
EmptyStruct {},
|
|
|
|
|
}
|
|
|
|
|
assert::<EmptyEnumVariant>();
|
2017-01-10 03:20:01 -06:00
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-10 03:20:01 -06:00
|
|
|
|
struct NonAsciiIdents {
|
2017-04-13 14:28:23 -05:00
|
|
|
|
σ: f64,
|
2017-01-10 03:20:01 -06:00
|
|
|
|
}
|
2017-01-11 13:02:24 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct EmptyBraced {}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct EmptyBracedDenyUnknown {}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct BracedSkipAll {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct BracedSkipAllDenyUnknown {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
struct EmptyTuple();
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct EmptyTupleDenyUnknown();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
struct TupleSkipAll(
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
u8
|
|
|
|
|
);
|
2017-01-11 13:02:24 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
2017-04-13 14:28:23 -05:00
|
|
|
|
struct TupleSkipAllDenyUnknown(
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
u8
|
|
|
|
|
);
|
2017-01-11 13:02:24 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum EmptyEnum {}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
enum EmptyEnumDenyUnknown {}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum EnumSkipAll {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Variant,
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
enum EmptyVariants {
|
|
|
|
|
Braced {},
|
|
|
|
|
Tuple(),
|
|
|
|
|
BracedSkip {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
},
|
2017-04-13 14:28:23 -05:00
|
|
|
|
TupleSkip(
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
u8
|
|
|
|
|
),
|
2017-01-11 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
enum EmptyVariantsDenyUnknown {
|
|
|
|
|
Braced {},
|
|
|
|
|
Tuple(),
|
|
|
|
|
BracedSkip {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
},
|
2017-04-13 14:28:23 -05:00
|
|
|
|
TupleSkip(
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
u8
|
|
|
|
|
),
|
2017-01-11 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct UnitDenyUnknown;
|
2017-04-05 19:34:13 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct EmptyArray {
|
|
|
|
|
empty: [X; 0],
|
|
|
|
|
}
|
2017-06-29 22:12:44 -05:00
|
|
|
|
|
|
|
|
|
enum Or<A, B> {
|
|
|
|
|
A(A),
|
|
|
|
|
B(B),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(untagged, remote = "Or")]
|
|
|
|
|
enum OrDef<A, B> {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
A(A),
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
B(B),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Str<'a>(&'a str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(remote = "Str")]
|
|
|
|
|
struct StrDef<'a>(&'a str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Remote<'a> {
|
|
|
|
|
#[serde(with = "OrDef")]
|
|
|
|
|
or: Or<u8, bool>,
|
|
|
|
|
#[serde(borrow, with = "StrDef")]
|
|
|
|
|
s: Str<'a>,
|
|
|
|
|
}
|
2017-07-26 01:52:06 -05:00
|
|
|
|
|
|
|
|
|
mod vis {
|
|
|
|
|
pub struct S;
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(remote = "S")]
|
|
|
|
|
pub struct SDef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This would not work if SDef::serialize / deserialize are private.
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct RemoteVisibility {
|
|
|
|
|
#[serde(with = "vis::SDef")]
|
|
|
|
|
s: vis::S,
|
|
|
|
|
}
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
2017-08-14 16:39:29 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-08-07 19:22:26 -05:00
|
|
|
|
enum ExternallyTaggedVariantWith {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Normal { f1: String },
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Newtype(X),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Tuple(String, u8),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct {
|
|
|
|
|
f1: String,
|
|
|
|
|
f2: u8,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_unit_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_unit_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Unit,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<ExternallyTaggedVariantWith>();
|
|
|
|
|
|
2017-08-14 16:39:29 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(tag = "t")]
|
|
|
|
|
enum InternallyTaggedVariantWith {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Normal { f1: String },
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Newtype(X),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct {
|
|
|
|
|
f1: String,
|
|
|
|
|
f2: u8,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_unit_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_unit_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Unit,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<InternallyTaggedVariantWith>();
|
|
|
|
|
|
2017-08-14 16:39:29 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(tag = "t", content = "c")]
|
|
|
|
|
enum AdjacentlyTaggedVariantWith {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Normal { f1: String },
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Newtype(X),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Tuple(String, u8),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct {
|
|
|
|
|
f1: String,
|
|
|
|
|
f2: u8,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_unit_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_unit_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Unit,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<AdjacentlyTaggedVariantWith>();
|
|
|
|
|
|
2017-08-14 16:39:29 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
enum UntaggedVariantWith {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Normal { f1: String },
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Newtype(X),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Tuple(String, u8),
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct {
|
|
|
|
|
f1: String,
|
|
|
|
|
f2: u8,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_unit_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_unit_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Unit,
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<UntaggedVariantWith>();
|
2017-09-09 13:34:08 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct StaticStrStruct<'a> {
|
|
|
|
|
a: &'a str,
|
|
|
|
|
b: &'static str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct StaticStrTupleStruct<'a>(&'a str, &'static str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct StaticStrNewtypeStruct(&'static str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum StaticStrEnum<'a> {
|
|
|
|
|
Struct {
|
|
|
|
|
a: &'a str,
|
|
|
|
|
b: &'static str,
|
|
|
|
|
},
|
|
|
|
|
Tuple(&'a str, &'static str),
|
|
|
|
|
Newtype(&'static str),
|
|
|
|
|
}
|
2017-11-03 12:08:02 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct SkippedStaticStr {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
skipped: &'static str,
|
|
|
|
|
other: isize,
|
|
|
|
|
}
|
|
|
|
|
assert::<SkippedStaticStr>();
|
2016-05-21 00:03:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-22 00:51:28 -05:00
|
|
|
|
|
2017-03-27 00:56:58 -05:00
|
|
|
|
fn assert<T: Serialize + DeserializeOwned>() {}
|
2016-07-22 10:49:51 -05:00
|
|
|
|
fn assert_ser<T: Serialize>() {}
|
2016-07-22 00:51:28 -05:00
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
trait SerializeWith {
|
2017-01-14 18:07:43 -06:00
|
|
|
|
fn serialize_with<S: Serializer>(_: &Self, _: S) -> StdResult<S::Ok, S::Error>;
|
2016-07-22 00:51:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
trait DeserializeWith: Sized {
|
2017-03-27 00:56:58 -05:00
|
|
|
|
fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error>;
|
2016-07-22 00:51:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
// Implements neither Serialize nor Deserialize
|
2017-02-14 19:36:50 -06:00
|
|
|
|
pub struct X;
|
2016-07-22 00:51:28 -05:00
|
|
|
|
|
2017-02-14 19:36:50 -06:00
|
|
|
|
pub fn ser_x<S: Serializer>(_: &X, _: S) -> StdResult<S::Ok, S::Error> {
|
2016-07-22 10:49:51 -05:00
|
|
|
|
unimplemented!()
|
2016-06-04 18:12:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 00:56:58 -05:00
|
|
|
|
pub fn de_x<'de, D: Deserializer<'de>>(_: D) -> StdResult<X, D::Error> {
|
2016-07-22 10:49:51 -05:00
|
|
|
|
unimplemented!()
|
2016-05-21 00:03:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 19:36:50 -06:00
|
|
|
|
mod both_x {
|
|
|
|
|
pub use super::{ser_x as serialize, de_x as deserialize};
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
impl SerializeWith for X {
|
2017-01-14 18:07:43 -06:00
|
|
|
|
fn serialize_with<S: Serializer>(_: &Self, _: S) -> StdResult<S::Ok, S::Error> {
|
2016-07-22 10:49:51 -05:00
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
2016-05-21 00:03:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
impl DeserializeWith for X {
|
2017-03-27 00:56:58 -05:00
|
|
|
|
fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error> {
|
2016-07-22 10:49:51 -05:00
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
2016-05-21 00:03:20 -05:00
|
|
|
|
}
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
pub fn serialize_some_unit_variant<S>(_: S) -> StdResult<S::Ok, S::Error>
|
|
|
|
|
where S: Serializer,
|
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn deserialize_some_unit_variant<'de, D>(_: D) -> StdResult<(), D::Error>
|
|
|
|
|
where D: Deserializer<'de>,
|
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-16 14:04:39 -05:00
|
|
|
|
pub fn serialize_some_other_variant<S>(_: &str, _: &u8, _: S) -> StdResult<S::Ok, S::Error>
|
2017-08-07 19:22:26 -05:00
|
|
|
|
where S: Serializer,
|
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn deserialize_some_other_variant<'de, D>(_: D) -> StdResult<(String, u8), D::Error>
|
|
|
|
|
where D: Deserializer<'de>,
|
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_zero(n: &u8) -> bool { *n == 0 }
|