-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrust.rs
82 lines (75 loc) · 1.55 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
74
75
76
77
78
79
80
81
82
/// test/rust.rs
use tsync::tsync;
use serde::Serialize;
/// Doc comments are preserved too!
#[tsync]
struct Book {
/// Name of the book.
name: String,
/// Chapters of the book.
chapters: Vec<Chapter>,
/// Reviews of the book
/// by users.
user_reviews: Option<Vec<String>>,
#[serde(flatten)]
book_type: BookType,
}
#[tsync]
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
/// Book struct with camelCase field names.
struct BookCamel {
/// Name of the book.
name: String,
/// Chapters of the book.
chapters: Vec<Chapter>,
/// Reviews of the book
/// by users.
user_reviews: Option<Vec<String>>,
}
/// Multiple line comments
/// are formatted on
/// separate lines
#[tsync]
struct Chapter {
title: String,
pages: u32,
}
#[tsync]
/// Generic struct test
struct PaginationResult<T> {
items: Vec<T>,
total_items: number,
}
#[tsync]
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
/// Generic struct test with camelCase field names.
struct PaginationResultCamel<T> {
items: Vec<T>,
total_items: number,
}
#[tsync]
#[derive(Serialize)]
/// Struct with flattened field.
struct Author {
name: String,
#[serde(flatten)]
name: AuthorName,
}
#[tsync]
#[derive(Serialize)]
struct AuthorName {
alias: Option<String>,
first_name: String,
last_name: String,
}
#[tsync]
#[derive(Serialize)]
#[serde(tag = "type")]
enum BookType {
#[serde(rename = "fiction")]
Fiction { genre: String },
#[serde(rename = "non-fiction")]
NonFiction { subject: String },
}