serde/test_suite/tests/test_remote.rs
2017-04-13 12:32:29 -07:00

201 lines
4.1 KiB
Rust

#[macro_use]
extern crate serde_derive;
extern crate serde;
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,
}
pub struct StructPub {
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
}
}
}
#[derive(Serialize, Deserialize)]
struct Test {
#[serde(with = "UnitDef")]
unit: remote::Unit,
#[serde(with = "PrimitivePrivDef")]
primitive_priv: remote::PrimitivePriv,
#[serde(with = "PrimitivePubDef")]
primitive_pub: remote::PrimitivePub,
#[serde(with = "NewtypePrivDef")]
newtype_priv: remote::NewtypePriv,
#[serde(with = "NewtypePubDef")]
newtype_pub: remote::NewtypePub,
#[serde(with = "TuplePrivDef")]
tuple_priv: remote::TuplePriv,
#[serde(with = "TuplePubDef")]
tuple_pub: remote::TuplePub,
#[serde(with = "StructPrivDef")]
struct_priv: remote::StructPriv,
#[serde(with = "StructPubDef")]
struct_pub: remote::StructPub,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::Unit")]
struct UnitDef;
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePriv")]
struct PrimitivePrivDef(
#[serde(getter = "remote::PrimitivePriv::get")]
u8
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePub")]
struct PrimitivePubDef(u8);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePriv")]
struct NewtypePrivDef(
#[serde(getter = "remote::NewtypePriv::get", with = "UnitDef")]
remote::Unit
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePub")]
struct NewtypePubDef(
#[serde(with = "UnitDef")]
remote::Unit
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePriv")]
struct TuplePrivDef(
#[serde(getter = "remote::TuplePriv::first")]
u8,
#[serde(getter = "remote::TuplePriv::second", with = "UnitDef")]
remote::Unit
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePub")]
struct TuplePubDef(
u8,
#[serde(with = "UnitDef")]
remote::Unit
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPriv")]
struct StructPrivDef {
#[serde(getter = "remote::StructPriv::a")]
a: u8,
#[serde(getter = "remote::StructPriv::b")]
#[serde(with= "UnitDef")]
b: remote::Unit,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPub")]
struct StructPubDef {
#[allow(dead_code)]
a: u8,
#[allow(dead_code)]
#[serde(with= "UnitDef")]
b: remote::Unit,
}
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)
}
}