Object initializer as function only argument

#[derive(Default)]
struct Options {
    x: f64,
    y: Option<f64>,
}

fn takes_1_arg(options: Options) { ... }

...

use takes::Options;

takes_1_arg(Options {
    x: 56,
    ..default()
})

This is about the closest you can get currently without macros. The closest I would probably ever want that still explicitly involved a struct would be

takes_1_arg(_ {
    x: 56,
    ..default()
})

With function defaults I would expect to be able to do this without ever defining an Options struct at all, and be able to write has_default_args(x = 56, ..default()) or even has_default_args(x=56). But these latter two forms have a whole lot of other implications.

1 Like