Crates.io | structstruck |
lib.rs | structstruck |
version | 0.4.1 |
source | src |
created_at | 2022-04-11 13:17:52.017122 |
updated_at | 2023-04-20 03:01:31.503814 |
description | Nested struct and enum definitions |
homepage | |
repository | https://github.com/jcaesar/structstruck |
max_upload_size | |
id | 565708 |
size | 44,153 |
Ever had a deeply nested JSON struct
{
"outer": {
"middle": {
"inner": {
"foo": "bar"
}
}
}
}
and wanted to write the Rust structs to handle that data just in the same nested way?
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:
structstruck::strike! {
enum Token {
Identifier(struct {
name: String,
}),
Punctuation(struct {
character: char,
}),
}
}
kube
.structstruck::strike! {
#[strikethrough[derive(Deserialize, Serialize, Clone, Debug, Validate, JsonSchema)]]
#[strikethrough[serde(rename_all = "camelCase")]]
#[derive(CustomResource)]
#[kube(
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<struct KafkaListener {
name: String,
port: u16,
r#type: String,
tls: bool,
}>,
config: HashMap<String, JsonValue>,
storage: struct {
r#type: String,
volumes: Vec<struct Volume {
id: Option<u64>,
r#type: String,
size: String,
delete_claim: bool,
}>,
},
},
zookeeper: struct {
#[validate(range(min = 1))]
replicas: u32,
storage: Volume,
},
entity_operator: struct {
topic_operator: Option<HashMap<String, JsonValue>>,
user_operator: Option<HashMap<String, JsonValue>>,
},
}
}