impl_new-0.1.1 has been yanked.
Impl New
A procedural macro to generate a new function for your struct.
Add to your project
Add this to your Cargo.toml
:
[]
= "0.1.0"
Or run this command in your workspace:
Usage
Is simple, just derive the impl_new::New
proc macro on your struct and it will generate a new
function for you.
For Named Fields
// The generated code will look like this:
// impl Foo {
// pub fn new(name: impl Into<String>, age: Into<usize>) -> Self {
// Self { name: name.into(), age: age.into() }
// }
// }
With Attributes
// The generated code will look like this:
// impl Foo {
// pub fn new(user_name: impl Into<String>, user_age: Into<usize>) -> Self {
// Self { name: user_name.into(), age: user_age.into() }
// }
// }
For Unnamed Fields
Note: The
#[impl_new(name = "name")]
attribute is required for unnamed fields.
String, usize);
// The generated code will look like this:
// impl Foo {
// pub fn new(name: impl Into<String>, age: Into<usize>) -> Self {
// Self(name.into(), age.into())
// }
// }
]
Attributes
#[impl_new(name = "name")]
: Use this attribute to change the name of the argument in the generatednew
function.
License
This project is licensed under the MIT license.