macro_rules! stru {
($($t:tt)*) => { ... };
}Expand description
Create anonymous struct object.
Just like how an object of named struct is created, you declare a field name, followed by a colon, and then its value. Finally, you separate each field with commas.
use structz::*;
let son_age = 12;
let father = stru! {
name: "John",
age: son_age + 25,
};
assert_eq!(field!(father.age), 37);When field’s value is omitted, it captures the value of the variable with the same name in the context.
use structz::*;
let name = "Smith";
let person = stru! {
name,
age: 30,
};
assert_eq!(field!(person.name), "Smith");