It’s sad that Rust has decided to settle with the builder pattern instead of implementing named arguments.
foo::some_func(foo::SomeFuncArgs{
a: 8,
b: Some(false),
..Default::default()
})
Personally I would be really happy if `..` could default to `..Default::default()` which would make this a lot cleaner. But even then needing to name a type for the argument struct is noisy. Language-integrated keyword arguments would make this a lot cleaner: foo::some_func(
a=8,
b=Some(false))I wouldn't mind if it worked this way "under the hood" but syntax sugar for passing that last argument as keyword arguments would be a fantastic quality of life improvement.
foo::some_func({
.a = 8,
.b = false
});
(I view this and std::span as the only two usable features in C++20, and pretty much everything else can go to the dustbin or the drawing board.) let mut foo = build_foo()
.with_a(8);
if need_to_set_b {
foo = foo.with_b(false);
}
let foo = foo.build();