2018-08-12 12:54:53 -05:00
|
|
|
|
// These just test that serde_derive 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)]
|
2020-06-26 23:32:40 -05:00
|
|
|
|
#![allow(
|
|
|
|
|
unknown_lints,
|
|
|
|
|
mixed_script_confusables,
|
2021-11-04 22:21:43 -05:00
|
|
|
|
clippy::items_after_statements,
|
|
|
|
|
clippy::missing_errors_doc,
|
|
|
|
|
clippy::missing_panics_doc,
|
|
|
|
|
clippy::must_use_candidate,
|
Ignore buggy nonstandard_macro_braces clippy lint
Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
error: use of irregular braces for `format_args!` macro
--> test_suite/tests/test_gen.rs:528:25
|
528 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
|
= note: `-D clippy::nonstandard-macro-braces` implied by `-D clippy::all`
help: consider writing `Deserialize`
--> test_suite/tests/test_gen.rs:528:25
|
528 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
error: use of irregular braces for `format_args!` macro
--> test_suite/tests/test_annotations.rs:1791:43
|
1791 | #[derive(Debug, PartialEq, Serialize, Deserialize)]
| ^^^^^^^^^^^
|
= note: `-D clippy::nonstandard-macro-braces` implied by `-D clippy::all`
help: consider writing `Deserialize`
--> test_suite/tests/test_annotations.rs:1791:43
|
1791 | #[derive(Debug, PartialEq, Serialize, Deserialize)]
| ^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
2021-07-02 22:57:57 -05:00
|
|
|
|
// Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
|
|
|
|
|
clippy::nonstandard_macro_braces,
|
2021-01-25 15:25:53 -06:00
|
|
|
|
clippy::ptr_arg,
|
2021-11-04 22:21:43 -05:00
|
|
|
|
clippy::too_many_lines,
|
2022-04-30 23:30:38 -05:00
|
|
|
|
clippy::trivially_copy_pass_by_ref,
|
|
|
|
|
clippy::type_repetition_in_bounds
|
2020-06-26 23:32:40 -05:00
|
|
|
|
)]
|
2017-02-24 17:32:13 -06:00
|
|
|
|
|
2018-12-31 20:44:24 -06:00
|
|
|
|
use serde::de::DeserializeOwned;
|
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
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-11-29 21:45:22 -06:00
|
|
|
|
use std::option::Option as StdOption;
|
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;
|
2017-11-29 21:45:22 -06:00
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct Option;
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct Some;
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
struct None;
|
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,
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
|
|
|
|
|
x: X,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
assert::<With<i32>>();
|
|
|
|
|
|
2017-02-14 19:36:50 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct WithTogether<T> {
|
|
|
|
|
t: T,
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(with = "both_x")]
|
|
|
|
|
x: X,
|
2017-02-14 19:36:50 -06:00
|
|
|
|
}
|
|
|
|
|
assert::<WithTogether<i32>>();
|
|
|
|
|
|
2016-07-22 10:49:51 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct WithRef<'a, T: 'a> {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
t: StdOption<&'a T>,
|
|
|
|
|
#[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
|
|
|
|
|
x: X,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
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,
|
2017-11-29 21:45:22 -06:00
|
|
|
|
option: StdOption<T>,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
boxed: Box<T>,
|
2017-11-29 21:45:22 -06:00
|
|
|
|
option_boxed: StdOption<Box<T>>,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
assert::<NoBounds<i32>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum EnumWith<T> {
|
|
|
|
|
Unit,
|
2018-04-30 03:41:22 -05:00
|
|
|
|
Newtype(#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X),
|
2016-07-22 10:49:51 -05:00
|
|
|
|
Tuple(
|
|
|
|
|
T,
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X,
|
2017-04-13 14:28:23 -05:00
|
|
|
|
),
|
2016-07-22 10:49:51 -05:00
|
|
|
|
Struct {
|
|
|
|
|
t: T,
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
|
|
|
|
|
x: X,
|
2017-04-13 14:28:23 -05:00
|
|
|
|
},
|
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)]
|
2018-04-30 03:41:22 -05:00
|
|
|
|
struct Newtype(#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X);
|
2016-07-22 10:49:51 -05:00
|
|
|
|
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,
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] 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-12-23 22:13:08 -06: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> {
|
2017-11-29 21:45:22 -06:00
|
|
|
|
a: StdOption<&'a str>,
|
|
|
|
|
b: StdOption<&'static str>,
|
2016-07-22 10:49:51 -05:00
|
|
|
|
}
|
|
|
|
|
assert_ser::<OptionStatic>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-12-23 22:13:08 -06:00
|
|
|
|
#[serde(bound = "D: SerializeWith + DeserializeWith")]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
struct WithTraits1<D, E> {
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(
|
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with"
|
|
|
|
|
)]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
d: D,
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(
|
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with",
|
|
|
|
|
bound = "E: SerializeWith + DeserializeWith"
|
|
|
|
|
)]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
e: E,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithTraits1<X, X>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2018-11-21 03:13:17 -06:00
|
|
|
|
#[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
struct WithTraits2<D, E> {
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(
|
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with"
|
|
|
|
|
)]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
d: D,
|
2018-04-30 03:41:22 -05:00
|
|
|
|
#[serde(
|
2018-07-08 21:02:44 -05:00
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
bound(serialize = "E: SerializeWith")
|
2018-04-30 03:41:22 -05:00
|
|
|
|
)]
|
|
|
|
|
#[serde(
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with",
|
|
|
|
|
bound(deserialize = "E: DeserializeWith")
|
|
|
|
|
)]
|
2016-07-22 10:49:51 -05:00
|
|
|
|
e: E,
|
|
|
|
|
}
|
|
|
|
|
assert::<WithTraits2<X, X>>();
|
2016-08-19 10:12:38 -05:00
|
|
|
|
|
2018-05-08 12:07:17 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(bound = "D: SerializeWith + DeserializeWith")]
|
|
|
|
|
enum VariantWithTraits1<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::<VariantWithTraits1<X, X>>();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2018-11-21 03:13:17 -06:00
|
|
|
|
#[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
|
2018-05-08 12:07:17 -05:00
|
|
|
|
enum VariantWithTraits2<D, E> {
|
|
|
|
|
#[serde(
|
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with"
|
|
|
|
|
)]
|
|
|
|
|
D(D),
|
|
|
|
|
#[serde(
|
2018-07-08 21:02:44 -05:00
|
|
|
|
serialize_with = "SerializeWith::serialize_with",
|
|
|
|
|
bound(serialize = "E: SerializeWith")
|
2018-05-08 12:07:17 -05:00
|
|
|
|
)]
|
|
|
|
|
#[serde(
|
|
|
|
|
deserialize_with = "DeserializeWith::deserialize_with",
|
|
|
|
|
bound(deserialize = "E: DeserializeWith")
|
|
|
|
|
)]
|
|
|
|
|
E(E),
|
|
|
|
|
}
|
|
|
|
|
assert::<VariantWithTraits2<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
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-10 03:20:01 -06:00
|
|
|
|
struct NonAsciiIdents {
|
2020-04-19 19:32:11 -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 {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
2017-01-11 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct BracedSkipAllDenyUnknown {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
2017-01-11 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
struct EmptyTuple();
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct EmptyTupleDenyUnknown();
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2018-04-30 03:41:22 -05:00
|
|
|
|
struct TupleSkipAll(#[serde(skip_deserializing)] u8);
|
2017-01-11 13:02:24 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
2018-04-30 03:41:22 -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
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
enum EmptyVariants {
|
|
|
|
|
Braced {},
|
|
|
|
|
Tuple(),
|
2017-12-23 22:24:57 -06:00
|
|
|
|
BracedSkip {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
},
|
2018-04-30 03:41:22 -05:00
|
|
|
|
TupleSkip(#[serde(skip_deserializing)] u8),
|
2017-01-11 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:02:15 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-01-11 13:02:24 -06:00
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
enum EmptyVariantsDenyUnknown {
|
|
|
|
|
Braced {},
|
|
|
|
|
Tuple(),
|
2017-12-23 22:24:57 -06:00
|
|
|
|
BracedSkip {
|
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
f: u8,
|
|
|
|
|
},
|
2018-04-30 03:41:22 -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> {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
A(A),
|
|
|
|
|
B(B),
|
2017-06-29 22:12:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Str<'a>(&'a str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(remote = "Str")]
|
|
|
|
|
struct StrDef<'a>(&'a str);
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Remote<'a> {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(with = "OrDef")]
|
|
|
|
|
or: Or<u8, bool>,
|
|
|
|
|
#[serde(borrow, with = "StrDef")]
|
|
|
|
|
s: Str<'a>,
|
2017-06-29 22:12:44 -05:00
|
|
|
|
}
|
2017-07-26 01:52:06 -05:00
|
|
|
|
|
2017-11-05 13:21:39 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum BorrowVariant<'a> {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(borrow, with = "StrDef")]
|
|
|
|
|
S(Str<'a>),
|
2017-11-05 13:21:39 -06:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 01:52:06 -05:00
|
|
|
|
mod vis {
|
2018-12-31 20:44:24 -06:00
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
2017-07-26 01:52:06 -05:00
|
|
|
|
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 {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(with = "vis::SDef")]
|
|
|
|
|
s: vis::S,
|
2017-07-26 01:52:06 -05:00
|
|
|
|
}
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
2017-08-14 16:39:29 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2018-03-27 03:56:05 -05:00
|
|
|
|
#[serde(remote = "Self")]
|
|
|
|
|
struct RemoteSelf;
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2017-08-07 19:22:26 -05:00
|
|
|
|
enum ExternallyTaggedVariantWith {
|
|
|
|
|
#[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),
|
|
|
|
|
|
2018-04-13 01:44:53 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct1 { x: X },
|
|
|
|
|
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
2017-12-23 22:24:57 -06:00
|
|
|
|
Struct { f1: String, f2: u8 },
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[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 {
|
2018-04-13 01:44:53 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[allow(dead_code)]
|
2018-04-13 01:44:53 -05:00
|
|
|
|
Newtype(X),
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
2018-04-13 01:44:53 -05:00
|
|
|
|
Struct1 { x: X },
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
2017-12-23 22:24:57 -06:00
|
|
|
|
Struct { f1: String, f2: u8 },
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[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 {
|
|
|
|
|
#[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),
|
|
|
|
|
|
2018-04-13 01:44:53 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct1 { x: X },
|
|
|
|
|
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
2017-12-23 22:24:57 -06:00
|
|
|
|
Struct { f1: String, f2: u8 },
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[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 {
|
|
|
|
|
#[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),
|
|
|
|
|
|
2018-04-13 01:44:53 -05:00
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct1 { x: X },
|
|
|
|
|
|
2017-08-07 19:22:26 -05:00
|
|
|
|
#[serde(serialize_with = "serialize_some_other_variant")]
|
|
|
|
|
#[serde(deserialize_with = "deserialize_some_other_variant")]
|
|
|
|
|
#[allow(dead_code)]
|
2017-12-23 22:24:57 -06:00
|
|
|
|
Struct { f1: String, f2: u8 },
|
2017-08-07 19:22:26 -05:00
|
|
|
|
|
|
|
|
|
#[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
|
|
|
|
|
2018-05-02 00:25:06 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct FlattenWith {
|
|
|
|
|
#[serde(flatten, serialize_with = "ser_x", deserialize_with = "de_x")]
|
|
|
|
|
x: X,
|
|
|
|
|
}
|
|
|
|
|
assert::<FlattenWith>();
|
|
|
|
|
|
2019-02-28 18:35:29 -06:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
|
struct FlattenDenyUnknown<T> {
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
t: T,
|
|
|
|
|
}
|
|
|
|
|
|
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> {
|
2017-12-23 22:13:08 -06:00
|
|
|
|
Struct { a: &'a str, b: &'static str },
|
2017-09-09 13:34:08 -05:00
|
|
|
|
Tuple(&'a str, &'static str),
|
|
|
|
|
Newtype(&'static str),
|
|
|
|
|
}
|
2017-11-03 12:08:02 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct SkippedStaticStr {
|
2017-12-23 22:24:57 -06:00
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
|
skipped: &'static str,
|
2017-11-03 12:08:02 -05:00
|
|
|
|
other: isize,
|
|
|
|
|
}
|
|
|
|
|
assert::<SkippedStaticStr>();
|
2017-11-05 14:18:39 -06:00
|
|
|
|
|
|
|
|
|
macro_rules! T {
|
2018-04-30 03:41:22 -05:00
|
|
|
|
() => {
|
|
|
|
|
()
|
|
|
|
|
};
|
2017-11-05 14:18:39 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct TypeMacro<T> {
|
|
|
|
|
mac: T!(),
|
|
|
|
|
marker: PhantomData<T>,
|
|
|
|
|
}
|
|
|
|
|
assert::<TypeMacro<X>>();
|
2018-03-15 12:02:40 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
struct BigArray {
|
|
|
|
|
#[serde(serialize_with = "<[_]>::serialize")]
|
|
|
|
|
array: [u8; 256],
|
|
|
|
|
}
|
|
|
|
|
assert_ser::<BigArray>();
|
2018-04-10 10:16:23 -05:00
|
|
|
|
|
|
|
|
|
trait AssocSerde {
|
|
|
|
|
type Assoc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct NoSerdeImpl;
|
|
|
|
|
impl AssocSerde for NoSerdeImpl {
|
|
|
|
|
type Assoc = u32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct AssocDerive<T: AssocSerde> {
|
2018-04-30 03:41:22 -05:00
|
|
|
|
assoc: T::Assoc,
|
2018-04-10 10:16:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert::<AssocDerive<NoSerdeImpl>>();
|
2018-04-12 15:44:32 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct AssocDeriveMulti<S, T: AssocSerde> {
|
|
|
|
|
s: S,
|
|
|
|
|
assoc: T::Assoc,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert::<AssocDeriveMulti<i32, NoSerdeImpl>>();
|
2018-05-06 23:49:37 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
#[serde(tag = "t", content = "c")]
|
|
|
|
|
enum EmptyAdjacentlyTagged {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Struct {},
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
Tuple(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_ser::<EmptyAdjacentlyTagged>();
|
2018-05-07 01:22:19 -05:00
|
|
|
|
|
|
|
|
|
mod restricted {
|
|
|
|
|
mod inner {
|
2018-12-31 20:44:24 -06:00
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
2018-05-07 01:22:19 -05:00
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Restricted {
|
|
|
|
|
pub(super) a: usize,
|
|
|
|
|
pub(in super::inner) b: usize,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-07 23:02:42 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
#[serde(tag = "t", content = "c")]
|
|
|
|
|
enum AdjacentlyTaggedVoid {}
|
2018-05-07 23:30:00 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum SkippedVariant<T> {
|
|
|
|
|
#[serde(skip)]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
T(T),
|
|
|
|
|
Unit,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert::<SkippedVariant<X>>();
|
2018-05-08 14:19:09 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2021-06-24 23:40:45 -05:00
|
|
|
|
struct ImplicitlyBorrowedOption<'a> {
|
2018-05-08 14:19:09 -05:00
|
|
|
|
option: std::option::Option<&'a str>,
|
|
|
|
|
}
|
2018-05-19 19:14:20 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
enum UntaggedNewtypeVariantWith {
|
|
|
|
|
Newtype(
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
X,
|
|
|
|
|
),
|
|
|
|
|
}
|
2018-05-20 15:53:29 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
#[serde(transparent)]
|
|
|
|
|
struct TransparentWith {
|
|
|
|
|
#[serde(serialize_with = "ser_x")]
|
|
|
|
|
#[serde(deserialize_with = "de_x")]
|
|
|
|
|
x: X,
|
|
|
|
|
}
|
2018-08-12 12:54:29 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
enum UntaggedWithBorrow<'a> {
|
|
|
|
|
Single(#[serde(borrow)] RelObject<'a>),
|
|
|
|
|
Many(#[serde(borrow)] Vec<RelObject<'a>>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
struct RelObject<'a> {
|
|
|
|
|
ty: &'a str,
|
|
|
|
|
id: String,
|
|
|
|
|
}
|
2019-02-15 20:32:13 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct FlattenSkipSerializing<T> {
|
|
|
|
|
#[serde(flatten, skip_serializing)]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
flat: T,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct FlattenSkipSerializingIf<T> {
|
|
|
|
|
#[serde(flatten, skip_serializing_if = "StdOption::is_none")]
|
|
|
|
|
flat: StdOption<T>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct FlattenSkipDeserializing<T> {
|
|
|
|
|
#[serde(flatten, skip_deserializing)]
|
|
|
|
|
flat: T,
|
|
|
|
|
}
|
2020-05-08 17:38:44 -05:00
|
|
|
|
|
|
|
|
|
// https://github.com/serde-rs/serde/issues/1804
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
enum Message {
|
|
|
|
|
#[serde(skip)]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
String(String),
|
|
|
|
|
#[serde(other)]
|
|
|
|
|
Unknown,
|
|
|
|
|
}
|
2020-05-10 00:52:49 -05:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
struct Packed {
|
|
|
|
|
x: u8,
|
|
|
|
|
y: u16,
|
|
|
|
|
}
|
2020-05-29 19:58:10 -05:00
|
|
|
|
|
|
|
|
|
macro_rules! deriving {
|
|
|
|
|
($field:ty) => {
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
struct MacroRules<'a> {
|
|
|
|
|
field: $field,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deriving!(&'a str);
|
2020-06-07 06:30:03 -05:00
|
|
|
|
|
|
|
|
|
macro_rules! mac {
|
|
|
|
|
($($tt:tt)*) => {
|
|
|
|
|
$($tt)*
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
struct BorrowLifetimeInsideMacro<'a> {
|
|
|
|
|
#[serde(borrow = "'a")]
|
|
|
|
|
f: mac!(Cow<'a, str>),
|
|
|
|
|
}
|
2021-01-25 15:25:53 -06:00
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
struct Struct {
|
|
|
|
|
#[serde(serialize_with = "vec_first_element")]
|
|
|
|
|
vec: Vec<Self>,
|
|
|
|
|
}
|
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 {
|
2017-12-23 22:13:08 -06:00
|
|
|
|
pub use super::{de_x as deserialize, ser_x as serialize};
|
2017-02-14 19:36:50 -06:00
|
|
|
|
}
|
|
|
|
|
|
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>
|
2017-12-23 22:13:08 -06:00
|
|
|
|
where
|
|
|
|
|
S: Serializer,
|
2017-08-07 19:22:26 -05:00
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn deserialize_some_unit_variant<'de, D>(_: D) -> StdResult<(), D::Error>
|
2017-12-23 22:13:08 -06:00
|
|
|
|
where
|
|
|
|
|
D: Deserializer<'de>,
|
2017-08-07 19:22:26 -05:00
|
|
|
|
{
|
|
|
|
|
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-12-23 22:13:08 -06:00
|
|
|
|
where
|
|
|
|
|
S: Serializer,
|
2017-08-07 19:22:26 -05:00
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn deserialize_some_other_variant<'de, D>(_: D) -> StdResult<(String, u8), D::Error>
|
2017-12-23 22:13:08 -06:00
|
|
|
|
where
|
|
|
|
|
D: Deserializer<'de>,
|
2017-08-07 19:22:26 -05:00
|
|
|
|
{
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 22:13:08 -06:00
|
|
|
|
pub fn is_zero(n: &u8) -> bool {
|
|
|
|
|
*n == 0
|
|
|
|
|
}
|
2021-01-25 15:25:53 -06:00
|
|
|
|
|
|
|
|
|
fn vec_first_element<T, S>(vec: &Vec<T>, serializer: S) -> StdResult<S::Ok, S::Error>
|
|
|
|
|
where
|
|
|
|
|
T: Serialize,
|
|
|
|
|
S: Serializer,
|
|
|
|
|
{
|
|
|
|
|
vec.first().serialize(serializer)
|
|
|
|
|
}
|
2021-02-28 06:43:54 -06:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
|
|
|
|
#[serde(tag = "tag")]
|
|
|
|
|
enum InternallyTagged {
|
|
|
|
|
#[serde(deserialize_with = "deserialize_generic")]
|
|
|
|
|
Unit,
|
|
|
|
|
|
|
|
|
|
#[serde(deserialize_with = "deserialize_generic")]
|
|
|
|
|
Newtype(i32),
|
|
|
|
|
|
|
|
|
|
#[serde(deserialize_with = "deserialize_generic")]
|
|
|
|
|
Struct { f1: String, f2: u8 },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deserialize_generic<'de, T, D>(deserializer: D) -> StdResult<T, D::Error>
|
|
|
|
|
where
|
|
|
|
|
T: Deserialize<'de>,
|
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
|
{
|
|
|
|
|
T::deserialize(deserializer)
|
|
|
|
|
}
|
2021-08-23 12:11:18 -05:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct RemotePacked {
|
2021-08-23 12:49:32 -05:00
|
|
|
|
pub a: u16,
|
|
|
|
|
pub b: u32,
|
2021-08-23 12:11:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 12:49:32 -05:00
|
|
|
|
#[derive(Serialize)]
|
2021-08-23 12:11:18 -05:00
|
|
|
|
#[repr(packed)]
|
|
|
|
|
#[serde(remote = "RemotePacked")]
|
|
|
|
|
pub struct RemotePackedDef {
|
2021-08-23 12:49:32 -05:00
|
|
|
|
a: u16,
|
|
|
|
|
b: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drop for RemotePackedDef {
|
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct RemotePackedNonCopy {
|
|
|
|
|
pub a: u16,
|
|
|
|
|
pub b: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
#[serde(remote = "RemotePackedNonCopy")]
|
|
|
|
|
pub struct RemotePackedNonCopyDef {
|
|
|
|
|
a: u16,
|
|
|
|
|
b: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drop for RemotePackedNonCopyDef {
|
|
|
|
|
fn drop(&mut self) {}
|
2021-08-23 12:11:18 -05:00
|
|
|
|
}
|