forked from Wulf/tsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rust.rs
65 lines (61 loc) · 1.34 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
/// test/rust.rs
use tsync::tsync;
/// Variants should to discriminated unions
/// The last serde/attribute combo matching the tag should be taken
#[derive(Serialize, Deserialize)]
#[serde(tag = "somethingelse")]
#[serde(renameAll = "kebab-case")]
#[serde(tag = "last_precedent")]
#[tsync]
enum Message {
/// Per Enum case Docs One
UnitCaseLeft,
/// Per Enum case Docs Two
RequestLongTake {
id: String,
method: String,
params: i32,
},
Response {
id: String,
result: NaiveDateTime,
},
}
/// The default enum conversion uses external tagging
#[tsync]
enum ExternalMessage {
/// Per Enum case Docs One
UnitCaseLeft,
/// Per Enum case Docs Two
RequestLongTake {
id: String,
method: String,
params: i32,
},
Response {
id: String,
result: 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(renameAll = "snake_case")]
enum AnimalTwo {
DogLongExtra = 2,
Cat,
}
/// Integer enums should follow rust discrimination if literals (doesn't evaluate expression)
#[derive(Serialize_repr)]
#[tsync]
enum Foo {
Bar, // 0
Baz = 123, // 123
Quux, // 124
}