-
Notifications
You must be signed in to change notification settings - Fork 10
/
rust.rs
73 lines (66 loc) · 1.61 KB
/
rust.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
/// test/rust.rs
use tsync::tsync;
/// Internally tagged enums have a key-value pair
/// that discrimate which variant it belongs to
#[derive(Serialize, Deserialize)]
#[serde(tag = "typetypetype")]
#[serde(renameAll = "kebab-case")]
#[serde(tag = "type")]
#[serde(rename_all = "UPPERCASE", tag = "type")]
#[tsync]
enum InternalTopping {
/// Tasty!
/// Not vegetarian
Pepperoni,
/// For cheese lovers
ExtraCheese { kind: String },
/// Custom toppings
/// May expire soon
Custom(CustomTopping),
}
/// Externally tagged enums ascribe the value to a key
/// that is the same as the variant name
#[tsync]
enum ExternalTopping {
/// Tasty!
/// Not vegetarian
Pepperoni,
/// For cheese lovers
ExtraCheese { kind: String },
/// Custom toppings
/// May expire soon
/// Note: this test case is specifically for specifying a single type in the tuple
Custom(CustomTopping),
}
#[tsync]
struct CustomTopping {
name: String,
expires_in: NaiveDateTime,
}
#[tsync]
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct CustomToppingCamel {
name: String,
expires_in: NaiveDateTime,
}
/// All Unit Enums go to union of constant strings
/// even if have explicit numeric annotations
/// There is no case renaming on default
#[tsync]
enum Animal {
Dog,
Cat,
}
#[tsync]
#[serde(rename_all = "snake_case")]
enum AnimalTwo {
DogLongExtra = 2,
Cat,
}
// Regression: if "serde(tag)" is specified, don't output a string.
#[tsync]
#[serde(tag = "type")]
enum Tagged {
Test // this should be { type: "Test" } in the TypeScript (not just the string "Test")
}