#[named_args]Expand description
Change the function’s arguments to an anonymous struct object and unpack it.
use structz::*;
#[named_args]
fn print_person(name: &str, age: u8, tags: Vec<&str>) {
println!("{} is {} years old and has tags {:?}", name, age, tags);
}
print_person(stru! {
tags: vec!["programmer", "artist"],
name: "Alice",
age: 30,
});The method receivers are not considered part of the anonymous struct object:
use structz::*;
struct Num(i32);
impl Num {
#[named_args]
fn add(&mut self, x: i32, y: i32) {
self.0 += x;
self.0 += y;
}
}
let mut num = Num(1);
num.add(stru! { x: 2, y: 3 });
assert_eq!(num.0, 6);