I guess it would be Fn(u32, u16, u8)
since it should be compatible with the positional form. But I am not sure what the implications would be. This is reaching the limit of my knowledge of Rust and the compiler
I added another alternative proposed in the discussion on the tracking issue. For better exposure I will paste it here too.
Parameters trait
Add a special trait, for example Params: Default
and have syntactic sugar for invoking functions that have their last argument implementing Params
.
Also add syntactic sugar for automatically defining an anonymous params struct.
For example:
#[derive(Params, Default)]
struct ExplicitParams {
herp: u8,
derp: i8,
}
// Use this form when you have many parameters
fn explicit(durr: &str, named: ExplicitParams) { ... }
// Use this from when you only have few parameters
// The params struct is automatically defined for you which takes away a lot of the verbosity
fn implicit(foo: &str = "xy", bar = 1u8) { ... }
fn main() {
explicit("unnamed", derp = 2);
// desugared: explicit("unnamed", ExplicitParams { derp: 2, ..Default::default() })
implicit(bar = 2);
// desugared: implicit(AnonymousStruct { foo: "xy", bar: 2 })
}
This would also take care of default arguments at the same time!