Just to toy with some proposed ideas for function call improvements. Using anonymous structs we can simulate structural types:
fn foo({a: &str, b: usize}) { /*...*/ }
Generic over anonymous structs, hat tip to @cramertj’s generics over tuples idea, if combined with proposed trait fields you get something serviceable at definition site, and very nice at call site.
trait Fields {
let a: usize
let b: &str
}
fn foo<F: Struct + Fields>(fields: ..F) { /*...*/ }
struct Bar { a: usize, b: &'static str, c: Vec<usize> };
impl Fields for Bar { let a = Self.a; let b = Self.b; }
let bar: Bar = /*...*/;
foo({..bar});
foo(..bar);
foo(a: 3, b: "test");
Maybe .. could be used for sugar for the Struct trait in the type position, e.g.
fn foo<F: ..Fields>(fields: ..F) { /*..*/ }
If Rust gets something like any for quick parametric types:
fn foo(fields: any ..Fields) { /*..*/ }
While this is still a little heavy on the definition side it would allow for traits such as Debug to be added more easily. I can’t figure out a good way to integrate default values in with this. Though between const, trait fields and a little sugar something feels possible.