Macro aoko::struct_new [−][src]
macro_rules! struct_new {
($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::{struct_new, assert_eqs};
struct_new!(
#[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\" }";
);