macro_rules! structs_new_decl {
    ($vis:vis struct $s_name:ident;) => { ... };
    ($(#[$attr:meta])* $vis:vis struct $s_name:ident $(<$($generic:tt),*>)? $(($($p_vis:vis $p_name:ident: $p_type:ty),* $(,)?))? $(where $($id:tt: $limit:tt),*)? {
        $($field_vis:vis $field:ident: $type:ty = $val:expr),* $(,)?
    }
    $($tail:tt)*) => { ... };
    () => { ... };
}
Expand description

Struct::new(...): define parameters and assigning user-defined values to fields directly.

Principles

Text replacement, automatic function generation.

Examples

use aoko::{structs_new_decl, assert_eqs};
 
structs_new_decl!(
    #[derive(Debug)]
    pub struct A<'a, T>(pub foo: T,) where T: Copy, T: Ord {
        pub bar: &'a str = "bar",
    }
    struct B {}
    struct C;
);
 
let test = A::new("foo");
 
assert_eqs!(
    "foo", test.foo;
    "bar", test.bar;
    format!("{:?}", test), "A { foo: \"foo\", bar: \"bar\" }";
);