Skip to content

Feature Request: Optional default values #70

Description

@luca992

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions