forked from serde-rs/serde
/
test_remote.rs
228 lines (175 loc) · 5.01 KB
/
test_remote.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#![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<T> {
pub value: T,
}
impl<T> StructGeneric<T> {
#[allow(dead_code)]
pub fn get_value(&self) -> &T {
&self.value
}
}
pub enum EnumGeneric<T> {
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<u8>,
#[serde(with = "EnumConcrete")]
enum_concrete: remote::EnumGeneric<u8>,
}
#[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<T> {
#[serde(getter = "remote::StructGeneric::get_value")]
value: T,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric<u8>")]
struct StructConcrete {
value: u8,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::EnumGeneric<u8>")]
enum EnumConcrete {
Variant(u8),
}
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)
}
}
impl<T> From<StructGenericWithGetterDef<T>> for remote::StructGeneric<T> {
fn from(def: StructGenericWithGetterDef<T>) -> Self {
remote::StructGeneric { value: def.value }
}
}