4 ms·
I would quite like to see some syntax sugar around this. If we could elide the type and made `...` equivalent to `..Default::default()` it would be a lot close
by wmanley 5y ago
I would quite like to see some syntax sugar around this. If we could elide the type and made `...` equivalent to `..Default::default()` it would be a lot closer to kwargs without having to introduce any new "real" features. So we could write:
f(arg1, arg2, _ {name: "Hello", address, ...})
instead of
f(arg1, arg2, MyKwargs {name: "Hello", address, ..Default::default()}
Using a struct for this feels natural as you get forwarding and non-exhaustiveness for adding additional fields for free.
- nicoburns 5y agoI would like this plus the ability to specify per-field defaults on structs like struct Foo { bar: String, // No default baz: Option<u32> = None, } I think this would give us 90% of what I would want from first-class named parameters.
- estebank 5y agoI'm looking for the time to write exactly that RFC. The parser, for what is worth, already parses that syntax for error recovery :) If you're interested, this is the last public conversation I had about these: https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234 https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-suga...
- skohan 5y agoOr you could just have named arguments with defaults, which is a highly ergonomic and well-tested solution to this problem.