derive-new
derive-new copied to clipboard
Feature Request: Optional default values
A feature from kotlin I miss:
class Foo(val x: String, val y: String, var z: String = "z")
val foo = Foo("x", "y", "z")
val foo1 = Foo("x", "y")
val foo2 = Foo("x", "y", "z2")
// foo == foo1
// foo != foo2
Would be nice if in rust you could do something similar like:
#[derive(new)]
struct Foo {
x: String,
y: String,
#[new(option, value = "z")]
z: String,
}
let foo = Foo::new("x", "y", "z");
let foo1 = Foo::new("x", "y", None);
let foo2 = Foo::new("x", "y", Some("z2");
// foo == foo1
// foo != foo2
It baffles my mind this whole crate along with this proposed feature is not already offered by the language itself with a decent syntax.
@pycaw something like new(z: impl Into<Option<String>>) is valid.