-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathlib.rs
107 lines (95 loc) · 1.9 KB
/
lib.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
#![allow(dead_code, clippy::disallowed_names)]
use std::{collections::BTreeSet, rc::Rc};
use chrono::NaiveDateTime;
use serde::Serialize;
use ts_rs::TS;
use uuid::Uuid;
#[derive(Serialize, TS)]
#[ts(rename_all = "lowercase")]
#[ts(export, export_to = "UserRole.ts")]
enum Role {
User,
#[ts(rename = "administrator")]
Admin,
}
#[derive(Serialize, TS)]
// when 'serde-compat' is enabled, ts-rs tries to use supported serde attributes.
#[serde(rename_all = "UPPERCASE")]
#[ts(export)]
enum Gender {
Male,
Female,
Other,
}
#[derive(Serialize, TS)]
#[ts(export)]
struct User {
user_id: i32,
first_name: String,
last_name: String,
role: Role,
family: Vec<User>,
#[ts(inline)]
gender: Gender,
token: Uuid,
#[ts(type = "string")]
created_at: NaiveDateTime,
}
#[derive(Serialize, TS)]
#[serde(tag = "type", rename_all = "snake_case")]
#[ts(export)]
enum Vehicle {
Bicycle { color: String },
Car { brand: String, color: String },
}
#[derive(Serialize, TS)]
#[ts(export)]
struct Point<T>
where
T: TS,
{
time: u64,
value: T,
}
#[derive(Serialize, TS)]
#[serde(default)]
#[ts(export)]
struct Series {
points: Vec<Point<u64>>,
}
#[derive(Serialize, TS)]
#[serde(tag = "kind", content = "d")]
#[ts(export)]
enum SimpleEnum {
A,
B,
}
#[derive(Serialize, TS)]
#[serde(tag = "kind", content = "data")]
#[ts(export)]
enum ComplexEnum {
A,
B { foo: String, bar: f64 },
W(SimpleEnum),
F { nested: SimpleEnum },
V(Vec<Series>),
U(Box<User>),
}
#[derive(Serialize, TS)]
#[serde(tag = "kind")]
#[ts(export)]
enum InlineComplexEnum {
A,
B { foo: String, bar: f64 },
W(SimpleEnum),
F { nested: SimpleEnum },
V(Vec<Series>),
U(Box<User>),
}
#[derive(Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
struct ComplexStruct {
#[serde(default)]
pub string_tree: Option<Rc<BTreeSet<String>>>,
}