forked from oxidecomputer/typify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderive.rs
207 lines (206 loc) · 6.1 KB
/
derive.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#![allow(clippy::redundant_closure_call)]
#![allow(clippy::needless_lifetimes)]
#![allow(clippy::match_single_binding)]
#![allow(clippy::clone_on_copy)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
#[doc = "`Fruit`"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"type\": \"object\","]
#[doc = " \"additionalProperties\": {"]
#[doc = " \"type\": \"string\""]
#[doc = " }"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, ExtraDerive)]
#[serde(transparent)]
pub struct Fruit(pub ::std::collections::HashMap<::std::string::String, ::std::string::String>);
impl ::std::ops::Deref for Fruit {
type Target = ::std::collections::HashMap<::std::string::String, ::std::string::String>;
fn deref(&self) -> &::std::collections::HashMap<::std::string::String, ::std::string::String> {
&self.0
}
}
impl ::std::convert::From<Fruit>
for ::std::collections::HashMap<::std::string::String, ::std::string::String>
{
fn from(value: Fruit) -> Self {
value.0
}
}
impl ::std::convert::From<&Fruit> for Fruit {
fn from(value: &Fruit) -> Self {
value.clone()
}
}
impl ::std::convert::From<::std::collections::HashMap<::std::string::String, ::std::string::String>>
for Fruit
{
fn from(
value: ::std::collections::HashMap<::std::string::String, ::std::string::String>,
) -> Self {
Self(value)
}
}
#[doc = "`FruitOrVeg`"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"oneOf\": ["]
#[doc = " {"]
#[doc = " \"title\": \"veg\","]
#[doc = " \"anyOf\": ["]
#[doc = " {"]
#[doc = " \"$ref\": \"#/defs/veggie\""]
#[doc = " }"]
#[doc = " ]"]
#[doc = " },"]
#[doc = " {"]
#[doc = " \"title\": \"fruit\","]
#[doc = " \"anyOf\": ["]
#[doc = " {"]
#[doc = " \"$ref\": \"#/defs/fruit\""]
#[doc = " }"]
#[doc = " ]"]
#[doc = " }"]
#[doc = " ]"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, ExtraDerive)]
#[serde(untagged)]
pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
}
impl ::std::convert::From<Veggie> for FruitOrVeg {
fn from(value: Veggie) -> Self {
Self::Veg(value)
}
}
impl ::std::convert::From<Fruit> for FruitOrVeg {
fn from(value: Fruit) -> Self {
Self::Fruit(value)
}
}
#[doc = "`Veggie`"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"type\": \"object\","]
#[doc = " \"required\": ["]
#[doc = " \"veggieLike\","]
#[doc = " \"veggieName\""]
#[doc = " ],"]
#[doc = " \"properties\": {"]
#[doc = " \"veggieLike\": {"]
#[doc = " \"description\": \"Do I like this vegetable?\","]
#[doc = " \"type\": \"boolean\""]
#[doc = " },"]
#[doc = " \"veggieName\": {"]
#[doc = " \"description\": \"The name of the vegetable.\","]
#[doc = " \"type\": \"string\""]
#[doc = " }"]
#[doc = " }"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, ExtraDerive)]
pub struct Veggie {
#[doc = "Do I like this vegetable?"]
#[serde(rename = "veggieLike")]
pub veggie_like: bool,
#[doc = "The name of the vegetable."]
#[serde(rename = "veggieName")]
pub veggie_name: ::std::string::String,
}
impl ::std::convert::From<&Veggie> for Veggie {
fn from(value: &Veggie) -> Self {
value.clone()
}
}
#[doc = "A representation of a person, company, organization, or place"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"$id\": \"https://example.com/arrays.schema.json\","]
#[doc = " \"title\": \"veggies\","]
#[doc = " \"description\": \"A representation of a person, company, organization, or place\","]
#[doc = " \"type\": \"object\","]
#[doc = " \"properties\": {"]
#[doc = " \"fruits\": {"]
#[doc = " \"type\": \"array\","]
#[doc = " \"items\": {"]
#[doc = " \"type\": \"string\""]
#[doc = " }"]
#[doc = " },"]
#[doc = " \"vegetables\": {"]
#[doc = " \"type\": \"array\","]
#[doc = " \"items\": {"]
#[doc = " \"$ref\": \"#/$defs/veggie\""]
#[doc = " }"]
#[doc = " }"]
#[doc = " }"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, ExtraDerive)]
pub struct Veggies {
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub fruits: ::std::vec::Vec<::std::string::String>,
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub vegetables: ::std::vec::Vec<Veggie>,
}
impl ::std::convert::From<&Veggies> for Veggies {
fn from(value: &Veggies) -> Self {
value.clone()
}
}
impl ::std::default::Default for Veggies {
fn default() -> Self {
Self {
fruits: Default::default(),
vegetables: Default::default(),
}
}
}