Input JSON Data
Rust Struct Code
Tool Instructions & Rust Struct Knowledge
Features
- Serde Macro Support: Automatically generates
#[derive(Serialize, Deserialize)]and#[serde(rename = "...")]attribute macros, which can be directly used withserde_jsonfor serialization and deserialization. - Snake Case Conversion: Follows Rust's
snake_casefield naming conventions, automatically converting camelCase or other formats in JSON and generating the corresponding mappings. - Safe Option: Supports wrapping all field types in
Option<T>to prevent panics caused by parsing failures when corresponding fields are missing in the JSON. - Smart Inference: Capable of distinguishing between
i64andf64(floating-point numbers), automatically inferringVec<T>, and intelligently filtering/evading Rust keywords (e.g.,typeconverts tor#type).
Rust and JSON (Serde)
- Serde Framework: The most famous serialization framework in the Rust ecosystem with extremely high performance. Typically, we need to add
serde = { version = "1.0", features = ["derive"] }andserde_json = "1.0"to our `Cargo.toml`. - Ownership and References: The default type generated by the tool is
String(which has ownership). This is the least likely to cause Lifetime issues during deserialization. For extremely high-performance scenarios, you can manually changeStringto&'a str, but you will need to handle the corresponding lifetime parameters.
