|
|
|
|
|
by masklinn
1873 days ago
|
|
I'm sure you can design schemas screwy enough that Rust can not even express them[0] but that one seems straightforward enough: #[derive(Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
enum X {
Foo { foobar: String },
Bar {
#[serde(skip_serializing_if = "Option::is_none")]
foobar: Option<f64>,
barbaz: String
}
}
[0] an enum of numbers would be an issue for instance, though I guess you could always use a `repr(C)` enum it might look a bit odd and naming would be difficult. |
|