bitpanda_csv/trade/asset/
metal.rs1#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Hash)]
7pub enum Metal {
8 Gold,
9 Palladium,
10 Platinum,
11 Silver,
12}
13
14impl ToString for Metal {
15 fn to_string(&self) -> String {
16 match self {
17 Self::Gold => "XAU",
18 Self::Palladium => "XPD",
19 Self::Platinum => "XPT",
20 Self::Silver => "XAG",
21 }
22 .to_string()
23 }
24}
25
26#[cfg(test)]
27mod test {
28
29 use super::*;
30
31 use pretty_assertions::assert_eq;
32 use std::io::Cursor;
33
34 #[test]
35 fn should_decode_asset() {
36 let csv = r#"id,metal
370,Gold
381,Palladium
392,Platinum
403,Silver
41"#;
42 let buffer = Cursor::new(csv);
43 let mut reader = csv::Reader::from_reader(buffer);
44 let mut fakes: Vec<Metal> = Vec::new();
45 for result in reader.deserialize::<Fake>() {
46 fakes.push(result.expect("failed to decode").metal);
47 }
48 assert_eq!(
49 fakes,
50 vec![
51 Metal::Gold,
52 Metal::Palladium,
53 Metal::Platinum,
54 Metal::Silver
55 ]
56 );
57 }
58
59 #[derive(Deserialize)]
60 #[allow(dead_code)]
61 struct Fake {
62 id: u64,
63 metal: Metal,
64 }
65}