1#![allow(clippy::redundant_field_names)]
2
3use serde_derive::{Deserialize, Serialize};
4
5mod 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 {
31        pub fn new(a: u8) -> Self {
32            PrimitivePriv(a)
33        }
34
35        pub fn get(&self) -> u8 {
36            self.0
37        }
38    }
39
40    impl NewtypePriv {
41        pub fn new(a: Unit) -> Self {
42            NewtypePriv(a)
43        }
44
45        pub fn get(&self) -> &Unit {
46            &self.0
47        }
48    }
49
50    impl TuplePriv {
51        pub fn new(a: u8, b: Unit) -> Self {
52            TuplePriv(a, b)
53        }
54
55        pub fn first(&self) -> u8 {
56            self.0
57        }
58
59        pub fn second(&self) -> &Unit {
60            &self.1
61        }
62    }
63
64    impl StructPriv {
65        pub fn new(a: u8, b: Unit) -> Self {
66            StructPriv { a: a, b: b }
67        }
68
69        pub fn a(&self) -> u8 {
70            self.a
71        }
72
73        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)]
84        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)]
95struct 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")]
135struct UnitDef;
136
137#[derive(Serialize, Deserialize)]
138#[serde(remote = "remote::PrimitivePriv")]
139struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8);
140
141#[derive(Serialize, Deserialize)]
142#[serde(remote = "remote::PrimitivePub")]
143struct PrimitivePubDef(u8);
144
145#[derive(Serialize, Deserialize)]
146#[serde(remote = "remote::NewtypePriv")]
147struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitDef")] remote::Unit);
148
149#[derive(Serialize, Deserialize)]
150#[serde(remote = "remote::NewtypePub")]
151struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
152
153#[derive(Serialize, Deserialize)]
154#[serde(remote = "remote::TuplePriv")]
155struct 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")]
162struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
163
164#[derive(Serialize, Deserialize)]
165#[serde(remote = "remote::StructPriv")]
166struct 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")]
177struct StructPubDef {
178    a: u8,
179
180    #[serde(with = "UnitDef")]
181    b: remote::Unit,
182}
183
184#[derive(Serialize, Deserialize)]
185#[serde(remote = "remote::StructGeneric")]
186struct StructGenericWithGetterDef<T> {
187    #[serde(getter = "remote::StructGeneric::get_value")]
188    value: T,
189}
190
191#[derive(Serialize, Deserialize)]
192#[serde(remote = "remote::StructGeneric<u8>")]
193struct StructConcrete {
194    value: u8,
195}
196
197#[derive(Serialize, Deserialize)]
198#[serde(remote = "remote::EnumGeneric<u8>")]
199enum EnumConcrete {
200    Variant(u8),
201}
202
203#[derive(Debug)]
204enum ErrorKind {
205    NotFound,
206    PermissionDenied,
207    #[allow(dead_code)]
208    ConnectionRefused,
209}
210
211#[derive(Serialize, Deserialize)]
212#[serde(remote = "ErrorKind")]
213#[non_exhaustive]
214enum ErrorKindDef {
215    NotFound,
216    PermissionDenied,
217    // ...
218}
219
220impl From<PrimitivePrivDef> for remote::PrimitivePriv {
221    fn from(def: PrimitivePrivDef) -> Self {
222        remote::PrimitivePriv::new(def.0)
223    }
224}
225
226impl From<NewtypePrivDef> for remote::NewtypePriv {
227    fn from(def: NewtypePrivDef) -> Self {
228        remote::NewtypePriv::new(def.0)
229    }
230}
231
232impl From<TuplePrivDef> for remote::TuplePriv {
233    fn from(def: TuplePrivDef) -> Self {
234        remote::TuplePriv::new(def.0, def.1)
235    }
236}
237
238impl From<StructPrivDef> for remote::StructPriv {
239    fn from(def: StructPrivDef) -> Self {
240        remote::StructPriv::new(def.a, def.b)
241    }
242}
243
244impl<T> From<StructGenericWithGetterDef<T>> for remote::StructGeneric<T> {
245    fn from(def: StructGenericWithGetterDef<T>) -> Self {
246        remote::StructGeneric { value: def.value }
247    }
248}
249