serde/test_suite/tests/test_remote.rs

209 lines
4.5 KiB
Rust
Raw Normal View History

2018-12-31 20:58:16 -06:00
#![allow(clippy::redundant_field_names)]
2018-01-13 16:28:12 -06:00
2018-12-31 20:44:24 -06:00
use serde::{Deserialize, Serialize};
2017-04-09 00:42:42 -05:00
mod remote {
pub struct Unit;
pub struct PrimitivePriv(u8);
pub struct PrimitivePub(pub u8);
pub struct NewtypePriv(Unit);
pub struct NewtypePub(pub Unit);
pub struct TuplePriv(u8, Unit);
pub struct TuplePub(pub u8, pub Unit);
pub struct StructPriv {
a: u8,
b: Unit,
}
2017-04-13 14:28:23 -05:00
pub struct StructPub {
2017-04-09 00:42:42 -05:00
pub a: u8,
pub b: Unit,
}
impl PrimitivePriv {
pub fn new(a: u8) -> Self {
PrimitivePriv(a)
}
pub fn get(&self) -> u8 {
self.0
}
}
impl NewtypePriv {
pub fn new(a: Unit) -> Self {
NewtypePriv(a)
}
pub fn get(&self) -> &Unit {
&self.0
}
}
impl TuplePriv {
pub fn new(a: u8, b: Unit) -> Self {
TuplePriv(a, b)
}
pub fn first(&self) -> u8 {
self.0
}
pub fn second(&self) -> &Unit {
&self.1
}
}
impl StructPriv {
pub fn new(a: u8, b: Unit) -> Self {
StructPriv { a: a, b: b }
}
pub fn a(&self) -> u8 {
self.a
}
pub fn b(&self) -> &Unit {
&self.b
}
}
pub struct StructGeneric<T> {
pub value: T,
}
pub enum EnumGeneric<T> {
Variant(T),
}
2017-04-09 00:42:42 -05:00
}
#[derive(Serialize, Deserialize)]
struct Test {
#[serde(with = "UnitDef")]
unit: remote::Unit,
2017-04-09 00:42:42 -05:00
#[serde(with = "PrimitivePrivDef")]
primitive_priv: remote::PrimitivePriv,
2017-04-09 00:42:42 -05:00
#[serde(with = "PrimitivePubDef")]
primitive_pub: remote::PrimitivePub,
2017-04-09 00:42:42 -05:00
#[serde(with = "NewtypePrivDef")]
newtype_priv: remote::NewtypePriv,
2017-04-09 00:42:42 -05:00
#[serde(with = "NewtypePubDef")]
newtype_pub: remote::NewtypePub,
2017-04-09 00:42:42 -05:00
#[serde(with = "TuplePrivDef")]
tuple_priv: remote::TuplePriv,
2017-04-09 00:42:42 -05:00
#[serde(with = "TuplePubDef")]
tuple_pub: remote::TuplePub,
2017-04-09 00:42:42 -05:00
#[serde(with = "StructPrivDef")]
struct_priv: remote::StructPriv,
2017-04-09 00:42:42 -05:00
#[serde(with = "StructPubDef")]
struct_pub: remote::StructPub,
#[serde(with = "StructConcrete")]
struct_concrete: remote::StructGeneric<u8>,
#[serde(with = "EnumConcrete")]
enum_concrete: remote::EnumGeneric<u8>,
2017-04-09 00:42:42 -05:00
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::Unit")]
struct UnitDef;
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePriv")]
2018-04-30 03:41:22 -05:00
struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8);
2017-04-09 00:42:42 -05:00
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePub")]
struct PrimitivePubDef(u8);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePriv")]
2018-04-30 03:41:22 -05:00
struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitDef")] remote::Unit);
2017-04-09 00:42:42 -05:00
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePub")]
2018-04-30 03:41:22 -05:00
struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
2017-04-09 00:42:42 -05:00
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePriv")]
struct TuplePrivDef(
2018-04-30 03:41:22 -05:00
#[serde(getter = "remote::TuplePriv::first")] u8,
#[serde(getter = "remote::TuplePriv::second", with = "UnitDef")] remote::Unit,
2017-04-13 14:28:23 -05:00
);
2017-04-09 00:42:42 -05:00
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePub")]
2018-04-30 03:41:22 -05:00
struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
2017-04-09 00:42:42 -05:00
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPriv")]
struct StructPrivDef {
#[serde(getter = "remote::StructPriv::a")]
a: u8,
2017-04-09 00:42:42 -05:00
#[serde(getter = "remote::StructPriv::b")]
2017-11-03 10:12:43 -05:00
#[serde(with = "UnitDef")]
2017-04-09 00:42:42 -05:00
b: remote::Unit,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPub")]
struct StructPubDef {
a: u8,
2017-04-09 00:42:42 -05:00
2017-11-03 10:12:43 -05:00
#[serde(with = "UnitDef")]
2017-04-09 00:42:42 -05:00
b: remote::Unit,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric::<u8>")]
struct StructConcrete {
value: u8,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::EnumGeneric::<u8>")]
enum EnumConcrete {
Variant(u8),
}
2017-04-09 00:42:42 -05:00
impl From<PrimitivePrivDef> for remote::PrimitivePriv {
fn from(def: PrimitivePrivDef) -> Self {
remote::PrimitivePriv::new(def.0)
}
}
impl From<NewtypePrivDef> for remote::NewtypePriv {
fn from(def: NewtypePrivDef) -> Self {
remote::NewtypePriv::new(def.0)
}
}
impl From<TuplePrivDef> for remote::TuplePriv {
fn from(def: TuplePrivDef) -> Self {
remote::TuplePriv::new(def.0, def.1)
}
}
impl From<StructPrivDef> for remote::StructPriv {
fn from(def: StructPrivDef) -> Self {
remote::StructPriv::new(def.a, def.b)
}
}