| Crates.io | new_macro |
| lib.rs | new_macro |
| version | 0.0.0 |
| created_at | 2023-06-21 10:44:40.203452+00 |
| updated_at | 2023-06-21 10:44:40.203452+00 |
| description | a proc_macro crate that generates a new struct with a new function |
| homepage | https://github.com/NightProg/new_macro |
| repository | https://github.com/NightProg/new_macro |
| max_upload_size | |
| id | 896083 |
| size | 5,674 |
The Rust macro derives a new function with attribute for simplified struct instantiation. It eliminates repetitive code and enhances readability.
To use the new_macro macro derive in your project, follow these steps:
new_macro crate in your code:use new_macro::New;
#[derive(New)]
struct MyStruct {
a: u32,
b: bool,
c: i32
// Other attributes...
}
The macro will generate a new function for your struct that accepts arguments:
let instance = MyStruct::new(34, true, 3); // Create an instance
Please note that the arguments passed to the new function should match the order and type of the struct's attributes.