#proc-macro #macro-derive #new

yanked new_macro

a proc_macro crate that generates a new struct with a new function

0.0.0 Jun 21, 2023

#7 in #new

MIT/Apache

5KB

new_macro

The Rust macro derives a new function with attribute for simplified struct instantiation. It eliminates repetitive code and enhances readability.

Usage

To use the new_macro macro derive in your project, follow these steps:

  1. Import the new_macro crate in your code:
use new_macro::New;
  1. Annotate your struct with the New attribute:
#[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.

Dependencies

~230–680KB
~16K SLoC