Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: default keyword in struct definitions #1

Open
nicoburns opened this issue Sep 14, 2018 · 0 comments
Open

Suggestion: default keyword in struct definitions #1

nicoburns opened this issue Sep 14, 2018 · 0 comments

Comments

@nicoburns
Copy link

This is an alternative to the #[optional(your_default_value_goes_here)] syntax. Instead struct definition could be name: Type default your_default_value_goes_here.

For example:

enum QuxKinds {
    A,
    B,
    C,
}

struct FooArguments {
    bar: String,
    baz: Option<String> default None,
    qux: QuxKinds       default QuxKinds::A,
}

which could then be instantiated (for example) in the following ways:

FooArguments {bar: "abc".to_owned()}
FooArguments {bar: "abc".to_owned(), baz: Some("cde".to_owned())}
FooArguments {bar: "abc".to_owned(), qux: QuxKinds::B}
FooArguments {bar: "abc".to_owned(), baz: None, qux: QuxKinds::B}

This would require a contextual default keyword, but I believe that wouldn't be problematic given that nothing was valid in that context previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant