3 ms·
This solution works sometimes, but it's not great if any of the fields don't have a sensible default.
by nicoburns 5y ago
This solution works sometimes, but it's not great if any of the fields don't have a sensible default.
- delta1 5y agoIn which case they should be explicitly provided.
- khuey 5y agoYou end up having to do struct Parameters { non_optional_parameter_1: Foo, non_optional_parameter_2: Bar, extra_options: ParametersWithDefault, } #[derive(Default)] struct ParametersWithDefault { ... } which is kind of annoying but not the end of the world.
- nicoburns 5y agoIt's a lot of small papercuts, but use module::{ foo, Parameters, ParametersWithDefault }; fn bar() { foo(Parameters { non_optional_parameter_1: Foo, non_optional_parameter_2: Bar, extra_options: ParametersWithDefault { optional_param: Baz, ...Default::default(), } }); } is a far cry in ergonomics from: use module::foo; fn bar() { foo(_ { non_optional_parameter_1: Foo, non_optional_parameter_2: Bar, optional_param: Baz, .. }); } Even just having to import the extra structs (and lookup the names) is a massive pain. Especially if you need to change to use a slightly different function.