#derivable #macro #structs #derive #macro-derive #paste #unnamed

macro bin new_derivable

Create new implementations with just a paste of a macro

2 unstable releases

0.2.0 Jan 30, 2022
0.1.0 Jan 30, 2022

#9 in #derivable

25 downloads per month

Custom license

9KB
111 lines

New Derivable

Automatically create a new implementation for your Structs (Unnamed, and Named).

use new_derivable::New;

#[derive(New,Debug)]
pub struct Human {
	pub name: String,
	pub age: i64
}

will ceate

impl Human {
	fn new(name: String, age: i64) -> Self {
		Self { name, age }
	}
}

so then you can do

fn main() {
	let human = Human::new(String::from("Justin"),69);
	println!("{:#?}", human);
}

Which will give us

Human {
	name: "Justin",
	age: 69
}

Dependencies

~2MB
~44K SLoC