json2struct: Compile-Time Struct Generation
A procedural macro for generating Rust structs from JSON-like structures with extensive compile-time type safety and configuration options.
Features
- Automatic Struct Generation: Create Rust structs from JSON-like syntax.
- Flexible Type Inference: Automatically infer types for fields.
- Serde Integration: Easily serialize and deserialize your structs.
- Compile-Time Type Checking: Catch errors during compilation.
- Configurable with Flags: Customize struct generation with powerful flags like
@debug
,@snake
,@derive
.
Installation
Add this crate as a dependency in your Cargo.toml
:
[]
= "0.1"
Basic Usage
Generate a simple struct from JSON-like syntax:
use json2struct;
json2struct!;
Output
Advanced Usage
Customize your structs with flags:
json2struct!;
Output
This example generates nested structs, debug derives, and a static JSON value
static COMPANY_JSON_VALUE: = new;
Supported Flags
Flag | Description | Example |
---|---|---|
@debug |
Adds Debug derive |
@debug |
@snake |
Renames fields to snake_case |
@snake |
@camel |
Renames fields to camelCase |
@camel |
@pascal |
Renames fields to PascalCase |
@pascal |
@derive(Type) |
Adds custom derives | @derive(PartialEq, Clone) |
@store_json |
Generates a static JSON value constant | @store_json |
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
This project is licensed under the MIT License.