Rust
Glue supports rust as a code generation target, allowing you to generate Rust structs and enums with Serde derives.
Simply run:
#Configuration
Rust generation currently supports:
When include_yaml is enabled, generated models include from_yaml/to_yaml helper methods.
Set serde_struct_derives: false to omit serde Serialize/Deserialize derives and serde attributes from generated structs, enums, union enums, and type alias newtypes.
If both options are combined, provide serde impls yourself before using the YAML helpers.
Use extra_derives to append additional Rust derive paths by generated shape. Entries must be Rust paths such as Hash, serde::Serialize, or schemars::JsonSchema.
#Example
For this Glue spec:
...generating Rust...
...will produce code similar to:
#Notes
- Optional fields are emitted as
Option<T>. - Arrays are emitted as
Vec<T>. intemitsisize,uintemitsusize, and fixed-width integers emit their Rust equivalents (i8,u64, etc.).- Tuples are emitted as native Rust tuples, e.g.
(String, isize). Record<K, V>is emitted asHashMap<K, V>.- Glue
typealiases are emitted as public tuple newtype structs. Aliases starting with_are inlined instead. - Type alias newtypes derive
Copy,PartialEq,Eq, andHashby default only for conservative copy/hash-safe shapes such as integers, bools, regular enums, and tuples of safe members. - Regular enums derive
CopyandHashby default. - By default, unions are emitted as generated
#[serde(untagged)]enums. - Anonymous structs are emitted as generated structs named from the owning field path.