Ever had a deeply nested JSON struct
json
{
"outer": {
"middle": {
"inner": {
"foo": "bar"
}
}
}
}
and wanted to write the Rust structs to handle that data just in the same nested way?
rust
struct Parent {
outer: struct {
middle: struct {
inner: struct {
foo: String,
}
}
}
}
This proc macro crate allows exactly that.
Check the docs on how exaclty.
For illustration, some more usecases:
an enum where every variant has its own struct, named exactly the same as the variant.
rust
structstruck::strike! {
enum Token {
Identifier(struct {
name: String,
}),
Punctuation(struct {
character: char,
}),
}
}
my original use case: conveniently write kubernetes custom resources with kube
.
```rust
structstruck::strike! {
group = "kafka.strimzi.io",
version = "v1beta2",
kind = "Kafka",
namespaced
)]
struct KafkaSpec {
kafka: struct KafkaCluster {
#[validate(length(min = 1))]
version: String,
#[validate(range(min = 1))]
replicas: u32,
listeners: Vec