#![allow(clippy::redundant_field_names)] use serde::{Deserialize, Serialize}; 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 } } pub struct StructGeneric { pub value: T, } impl StructGeneric { #[allow(dead_code)] pub fn get_value(&self) -> &T { &self.value } } pub enum EnumGeneric { Variant(T), } } #[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, #[serde(with = "StructConcrete")] struct_concrete: remote::StructGeneric, #[serde(with = "EnumConcrete")] enum_concrete: remote::EnumGeneric, } #[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 { a: u8, #[serde(with = "UnitDef")] b: remote::Unit, } #[derive(Serialize, Deserialize)] #[serde(remote = "remote::StructGeneric")] struct StructGenericWithGetterDef { #[serde(getter = "remote::StructGeneric::get_value")] value: T, } #[derive(Serialize, Deserialize)] #[serde(remote = "remote::StructGeneric")] struct StructConcrete { value: u8, } #[derive(Serialize, Deserialize)] #[serde(remote = "remote::EnumGeneric")] enum EnumConcrete { Variant(u8), } impl From for remote::PrimitivePriv { fn from(def: PrimitivePrivDef) -> Self { remote::PrimitivePriv::new(def.0) } } impl From for remote::NewtypePriv { fn from(def: NewtypePrivDef) -> Self { remote::NewtypePriv::new(def.0) } } impl From for remote::TuplePriv { fn from(def: TuplePrivDef) -> Self { remote::TuplePriv::new(def.0, def.1) } } impl From for remote::StructPriv { fn from(def: StructPrivDef) -> Self { remote::StructPriv::new(def.a, def.b) } } impl From> for remote::StructGeneric { fn from(def: StructGenericWithGetterDef) -> Self { remote::StructGeneric { value: def.value } } }