1 #![allow(clippy::redundant_field_names)] 2 3 use serde_derive::{Deserialize, Serialize}; 4 5 mod remote { 6 pub struct Unit; 7 8 pub struct PrimitivePriv(u8); 9 10 pub struct PrimitivePub(pub u8); 11 12 pub struct NewtypePriv(Unit); 13 14 pub struct NewtypePub(pub Unit); 15 16 pub struct TuplePriv(u8, Unit); 17 18 pub struct TuplePub(pub u8, pub Unit); 19 20 pub struct StructPriv { 21 a: u8, 22 b: Unit, 23 } 24 25 pub struct StructPub { 26 pub a: u8, 27 pub b: Unit, 28 } 29 30 impl PrimitivePriv { new(a: u8) -> Self31 pub fn new(a: u8) -> Self { 32 PrimitivePriv(a) 33 } 34 get(&self) -> u835 pub fn get(&self) -> u8 { 36 self.0 37 } 38 } 39 40 impl NewtypePriv { new(a: Unit) -> Self41 pub fn new(a: Unit) -> Self { 42 NewtypePriv(a) 43 } 44 get(&self) -> &Unit45 pub fn get(&self) -> &Unit { 46 &self.0 47 } 48 } 49 50 impl TuplePriv { new(a: u8, b: Unit) -> Self51 pub fn new(a: u8, b: Unit) -> Self { 52 TuplePriv(a, b) 53 } 54 first(&self) -> u855 pub fn first(&self) -> u8 { 56 self.0 57 } 58 second(&self) -> &Unit59 pub fn second(&self) -> &Unit { 60 &self.1 61 } 62 } 63 64 impl StructPriv { new(a: u8, b: Unit) -> Self65 pub fn new(a: u8, b: Unit) -> Self { 66 StructPriv { a: a, b: b } 67 } 68 a(&self) -> u869 pub fn a(&self) -> u8 { 70 self.a 71 } 72 b(&self) -> &Unit73 pub fn b(&self) -> &Unit { 74 &self.b 75 } 76 } 77 78 pub struct StructGeneric<T> { 79 pub value: T, 80 } 81 82 impl<T> StructGeneric<T> { 83 #[allow(dead_code)] get_value(&self) -> &T84 pub fn get_value(&self) -> &T { 85 &self.value 86 } 87 } 88 89 pub enum EnumGeneric<T> { 90 Variant(T), 91 } 92 } 93 94 #[derive(Serialize, Deserialize)] 95 struct Test { 96 #[serde(with = "UnitDef")] 97 unit: remote::Unit, 98 99 #[serde(with = "PrimitivePrivDef")] 100 primitive_priv: remote::PrimitivePriv, 101 102 #[serde(with = "PrimitivePubDef")] 103 primitive_pub: remote::PrimitivePub, 104 105 #[serde(with = "NewtypePrivDef")] 106 newtype_priv: remote::NewtypePriv, 107 108 #[serde(with = "NewtypePubDef")] 109 newtype_pub: remote::NewtypePub, 110 111 #[serde(with = "TuplePrivDef")] 112 tuple_priv: remote::TuplePriv, 113 114 #[serde(with = "TuplePubDef")] 115 tuple_pub: remote::TuplePub, 116 117 #[serde(with = "StructPrivDef")] 118 struct_priv: remote::StructPriv, 119 120 #[serde(with = "StructPubDef")] 121 struct_pub: remote::StructPub, 122 123 #[serde(with = "StructConcrete")] 124 struct_concrete: remote::StructGeneric<u8>, 125 126 #[serde(with = "EnumConcrete")] 127 enum_concrete: remote::EnumGeneric<u8>, 128 129 #[serde(with = "ErrorKindDef")] 130 io_error_kind: ErrorKind, 131 } 132 133 #[derive(Serialize, Deserialize)] 134 #[serde(remote = "remote::Unit")] 135 struct UnitDef; 136 137 #[derive(Serialize, Deserialize)] 138 #[serde(remote = "remote::PrimitivePriv")] 139 struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8); 140 141 #[derive(Serialize, Deserialize)] 142 #[serde(remote = "remote::PrimitivePub")] 143 struct PrimitivePubDef(u8); 144 145 #[derive(Serialize, Deserialize)] 146 #[serde(remote = "remote::NewtypePriv")] 147 struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitDef")] remote::Unit); 148 149 #[derive(Serialize, Deserialize)] 150 #[serde(remote = "remote::NewtypePub")] 151 struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit); 152 153 #[derive(Serialize, Deserialize)] 154 #[serde(remote = "remote::TuplePriv")] 155 struct TuplePrivDef( 156 #[serde(getter = "remote::TuplePriv::first")] u8, 157 #[serde(getter = "remote::TuplePriv::second", with = "UnitDef")] remote::Unit, 158 ); 159 160 #[derive(Serialize, Deserialize)] 161 #[serde(remote = "remote::TuplePub")] 162 struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit); 163 164 #[derive(Serialize, Deserialize)] 165 #[serde(remote = "remote::StructPriv")] 166 struct StructPrivDef { 167 #[serde(getter = "remote::StructPriv::a")] 168 a: u8, 169 170 #[serde(getter = "remote::StructPriv::b")] 171 #[serde(with = "UnitDef")] 172 b: remote::Unit, 173 } 174 175 #[derive(Serialize, Deserialize)] 176 #[serde(remote = "remote::StructPub")] 177 struct StructPubDef { 178 a: u8, 179 180 #[serde(with = "UnitDef")] 181 b: remote::Unit, 182 } 183 184 #[derive(Serialize, Deserialize)] 185 #[serde(remote = "remote::StructGeneric")] 186 struct StructGenericWithGetterDef<T> { 187 #[serde(getter = "remote::StructGeneric::get_value")] 188 value: T, 189 } 190 191 #[derive(Serialize, Deserialize)] 192 #[serde(remote = "remote::StructGeneric<u8>")] 193 struct StructConcrete { 194 value: u8, 195 } 196 197 #[derive(Serialize, Deserialize)] 198 #[serde(remote = "remote::EnumGeneric<u8>")] 199 enum EnumConcrete { 200 Variant(u8), 201 } 202 203 #[derive(Debug)] 204 enum ErrorKind { 205 NotFound, 206 PermissionDenied, 207 #[allow(dead_code)] 208 ConnectionRefused, 209 } 210 211 #[derive(Serialize, Deserialize)] 212 #[serde(remote = "ErrorKind")] 213 #[non_exhaustive] 214 enum ErrorKindDef { 215 NotFound, 216 PermissionDenied, 217 // ... 218 } 219 220 impl From<PrimitivePrivDef> for remote::PrimitivePriv { from(def: PrimitivePrivDef) -> Self221 fn from(def: PrimitivePrivDef) -> Self { 222 remote::PrimitivePriv::new(def.0) 223 } 224 } 225 226 impl From<NewtypePrivDef> for remote::NewtypePriv { from(def: NewtypePrivDef) -> Self227 fn from(def: NewtypePrivDef) -> Self { 228 remote::NewtypePriv::new(def.0) 229 } 230 } 231 232 impl From<TuplePrivDef> for remote::TuplePriv { from(def: TuplePrivDef) -> Self233 fn from(def: TuplePrivDef) -> Self { 234 remote::TuplePriv::new(def.0, def.1) 235 } 236 } 237 238 impl From<StructPrivDef> for remote::StructPriv { from(def: StructPrivDef) -> Self239 fn from(def: StructPrivDef) -> Self { 240 remote::StructPriv::new(def.a, def.b) 241 } 242 } 243 244 impl<T> From<StructGenericWithGetterDef<T>> for remote::StructGeneric<T> { from(def: StructGenericWithGetterDef<T>) -> Self245 fn from(def: StructGenericWithGetterDef<T>) -> Self { 246 remote::StructGeneric { value: def.value } 247 } 248 } 249