#[derive(New)]
{
// Attributes available to this derive:
#[new]
}
Expand description
Creates an implementation for a new() function that initializes
the attached struct.
ยงExample
use shebling_codegen::New;
#[derive(New)]
struct Foo {
// Any type that implements Into<String> can be used as the
// first parameter for Foo::new.
#[new(into)]
foo: String,
// With boxed types, the generated constructor will take
// the unboxed type as a parameter.
bar: Box<u32>,
}
let foo = Foo::new("Foo", 10);
assert_eq!((foo.foo, *foo.bar), ("Foo".into(), 10));