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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
use serde::de::{self, MapAccess, Visitor};
use serde::{Deserialize, Deserializer};
use std::fmt;
pub enum Currency {
USD,
None,
}
pub enum Type {
PRIVATE,
Misc,
Right,
Preference,
MLP,
RoyaltyTrst,
CDI,
TrackingStk,
DutchCert,
CommonStock,
NVDR,
OpenEndFund,
Unit,
SavingsShare,
GDR,
REIT,
StapledSecurity,
ClosedEndFund,
SDR,
ForeignSh,
NYRegShrs,
ETP,
PUBLIC,
LtdPart,
EquityWRT,
ADR,
Receipt,
None,
}
pub struct Symbol {
pub currency: Currency,
pub description: String,
pub display_symbol: String,
pub figi: String,
pub isin: String,
pub mic: String,
pub share_class_figi: String,
pub symbol: String,
pub symbol2: String,
pub typee: Type,
}
// AI generated deserialize since symbol contains 'type' and so on
impl<'de> Deserialize<'de> for Symbol {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
enum Field {
Currency,
Description,
DisplaySymbol,
Figi,
Isin,
Mic,
ShareClassFigi,
Symbol,
Symbol2,
Type,
}
impl<'de> Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Field, D::Error>
where
D: Deserializer<'de>,
{
struct FieldVisitor;
impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("field identifier")
}
fn visit_str<E>(self, value: &str) -> Result<Field, E>
where
E: de::Error,
{
match value {
"currency" => Ok(Field::Currency),
"description" => Ok(Field::Description),
"displaySymbol" => Ok(Field::DisplaySymbol),
"figi" => Ok(Field::Figi),
"isin" => Ok(Field::Isin),
"mic" => Ok(Field::Mic),
"shareClassFIGI" => Ok(Field::ShareClassFigi),
"symbol" => Ok(Field::Symbol),
"symbol2" => Ok(Field::Symbol2),
"type" => Ok(Field::Type),
_ => Err(de::Error::unknown_field(value, FIELDS)),
}
}
}
deserializer.deserialize_identifier(FieldVisitor)
}
}
struct SymbolVisitor;
impl<'de> Visitor<'de> for SymbolVisitor {
type Value = Symbol;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("struct Symbol")
}
fn visit_map<V>(self, mut map: V) -> Result<Symbol, V::Error>
where
V: MapAccess<'de>,
{
let mut currency = None;
let mut description = None;
let mut display_symbol = None;
let mut figi = None;
let mut isin = None;
let mut mic = None;
let mut share_class_figi = None;
let mut symbol = None;
let mut symbol2 = None;
let mut typee = None;
while let Some(key) = map.next_key()? {
match key {
Field::Currency => {
if currency.is_some() {
return Err(de::Error::duplicate_field("current"));
}
let string_value: &str = map.next_value()?;
let enum_value = match string_value.trim() {
"USD" => Currency::USD,
"" => Currency::None,
_ => {
return Err(de::Error::custom(format!(
"couldn't match {string_value} to a currency"
)));
}
};
currency = Some(enum_value);
}
Field::Description => {
if description.is_some() {
return Err(de::Error::duplicate_field("description"));
}
description = Some(map.next_value()?);
}
Field::DisplaySymbol => {
if display_symbol.is_some() {
return Err(de::Error::duplicate_field("displaySymbol"));
}
display_symbol = Some(map.next_value()?);
}
Field::Figi => {
if figi.is_some() {
return Err(de::Error::duplicate_field("figi"));
}
figi = Some(map.next_value()?);
}
Field::Isin => {
if isin.is_some() {
return Err(de::Error::duplicate_field("isin"));
}
isin = Some(map.next_value()?);
}
Field::Mic => {
if mic.is_some() {
return Err(de::Error::duplicate_field("mic"));
}
mic = Some(map.next_value()?);
}
Field::ShareClassFigi => {
if share_class_figi.is_some() {
return Err(de::Error::duplicate_field("shareClassFIGI"));
}
share_class_figi = Some(map.next_value()?);
}
Field::Symbol => {
if symbol.is_some() {
return Err(de::Error::duplicate_field("symbol"));
}
symbol = Some(map.next_value()?);
}
Field::Symbol2 => {
if symbol2.is_some() {
return Err(de::Error::duplicate_field("symbol2"));
}
symbol2 = Some(map.next_value()?);
}
Field::Type => {
if typee.is_some() {
return Err(de::Error::duplicate_field("type"));
}
let string_value: &str = map.next_value()?;
let enum_value = match string_value.trim() {
"PRIVATE" => Type::PRIVATE,
"Misc." => Type::Misc,
"Right" => Type::Right,
"Preference" => Type::Preference,
"MLP" => Type::MLP,
"Royalty Trst" => Type::RoyaltyTrst,
"CDI" => Type::CDI,
"Tracking Stk" => Type::TrackingStk,
"Dutch Cert" => Type::DutchCert,
"Common Stock" => Type::CommonStock,
"NVDR" => Type::NVDR,
"Open-End Fund" => Type::OpenEndFund,
"Unit" => Type::Unit,
"Savings Share" => Type::SavingsShare,
"GDR" => Type::GDR,
"REIT" => Type::REIT,
"Stapled Security" => Type::StapledSecurity,
"Closed-End Fund" => Type::ClosedEndFund,
"SDR" => Type::SDR,
"Foreign Sh." => Type::ForeignSh,
"NY Reg Shrs" => Type::NYRegShrs,
"ETP" => Type::ETP,
"PUBLIC" => Type::PUBLIC,
"Ltd Part" => Type::LtdPart,
"Equity WRT" => Type::EquityWRT,
"ADR" => Type::ADR,
"Receipt" => Type::Receipt,
"" => Type::None,
_ => {
return Err(de::Error::custom(format!(
"couldn't match {string_value} to a type"
)));
}
};
typee = Some(enum_value);
}
}
}
Ok(Symbol {
currency: currency.ok_or_else(|| de::Error::missing_field("current"))?,
description: description
.ok_or_else(|| de::Error::missing_field("description"))?,
display_symbol: display_symbol
.ok_or_else(|| de::Error::missing_field("displaySymbol"))?,
figi: figi.ok_or_else(|| de::Error::missing_field("figi"))?,
isin: isin.ok_or_else(|| de::Error::missing_field("isin"))?,
mic: mic.ok_or_else(|| de::Error::missing_field("mic"))?,
share_class_figi: share_class_figi
.ok_or_else(|| de::Error::missing_field("shareClassFIGI"))?,
symbol: symbol.ok_or_else(|| de::Error::missing_field("symbol"))?,
symbol2: symbol2.ok_or_else(|| de::Error::missing_field("symbol2"))?,
typee: typee.ok_or_else(|| de::Error::missing_field("type"))?,
})
}
}
const FIELDS: &[&str] = &[
"current",
"description",
"displaySymbol",
"figi",
"isin",
"mic",
"shareClassFIGI",
"symbol",
"symbol2",
"type",
];
deserializer.deserialize_struct("Symbol", FIELDS, SymbolVisitor)
}
}