new_macro

Crates.ionew_macro
lib.rsnew_macro
version0.0.0
sourcesrc
created_at2023-06-21 10:44:40.203452
updated_at2023-06-21 10:44:40.203452
descriptiona proc_macro crate that generates a new struct with a new function
homepagehttps://github.com/NightProg/new_macro
repositoryhttps://github.com/NightProg/new_macro
max_upload_size
id896083
size5,674
NightProg (NightProg)

documentation

README

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.

Commit count: 13

cargo fmt