DataStruct.rs
This is a procedural macro library to automatically generate duplicate code for pure data structures.
What can this lib do?
The library provides a derive macro to automatically implement "plain methods" for data structures.
Currently Available:
- Default: Standard
Default, lib-specificDataStruct::data_defaultand constant defaultConstDataStruct::DEFAULT. - Debug: Manual
Debugfilter. - Comparison: Standard
Eq,PartialEq,Ord,PartialOrd. - Operations: Standard
Add(Assign),Sub(Assign),Mul(Assign),Div(Assign).
Unlike standard derive macros, the DataStruct macro accepts user-defined behaviors without
writing implementation code.
Quick Start
For full documentation, read it here.
Let's start with this example structure:
First, add datastruct to your dependencies. The core entry point of the library is DataStruct macro.
use DataStruct;
The #[dstruct(xxx)] is used to configure the basic options of the code-generator. In this example,
debug means that the Debug trait will be implemented.
The #[dfield(xxx)] is used to configure field-specific options of the code-generator. In this example,
no_debug means that this field will not be included in the debug output.
use DataStruct;
let person = Person ;
println!;
// Output:
// Person {
// age: 22,
// name: "James",
// }
Limitations
Currently, the library can only generate code for typical structure, and tuple structure is not supported.
Besides, most IDE-support cannot offer full completion for macro-generated code, compared with manual implementation.