macro_rules! meta_default_constructor { ( {$($imports: stmt);* $(;)?} $($tt: tt)* ) => { ... }; ( @ty [$func: expr] ::$($ty: ident)::* ::< $($tt: tt)* ) => { ... }; ( @ty [$func: expr] ::$($ty: ident)::* {$($tt: tt)*} ) => { ... }; ( @ty [$func: expr] $($ty: ident)::* ::< $($tt: tt)* ) => { ... }; ( @ty [$func: expr] $($ty: ident)::* {$($tt: tt)*} ) => { ... }; ( @generics [$func: expr] [$($ty: tt)*] [$($generics: tt)*] ::<$lt: lifetime, $($tt: tt)* ) => { ... }; ( @generics [$func: expr] [$($ty: tt)*] [$($generics: tt)*] ::<$lt: lifetime> $($tt: tt)* ) => { ... }; ( @generics [$func: expr] [$($ty: tt)*] [$($generics: tt)*] ::<$($gty: ty),* $(,)?> $($tt: tt)* ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: $block: block $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: ::$($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: $($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: @$effect:ident ::$($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: @$effect:ident $($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: @$effect:ident $expr: expr $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {$field: ident: $expr: expr $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [] {} {$($field: ident: $expr: expr),*} ) => { ... }; ( @fields [$func: expr] [$($ty: tt)*] [$($generics: tt)*] {} {$($field: ident: $expr: expr),*} ) => { ... }; }
Expand description
The meta macro.
§Syntax
meta_default_constructor!(
// scoped imports, optional, must be in braces `{..}`
{
import std::future::Future;
import rand::prelude::*;
}
// conversion function, required
[Into::into]
// struct name, required
MyStruct
// generics, optional, must be in brackets `[..]`
// this is equivalent to specifying `::<f32, String>`
[f32, String]
// fields
{
// name value pairs like normal structs
//
// value is converted via the conversion function
// name: Into::into(value),
name: value,
// use `effect` boxed to do another conversion, see the `effect!` macro.
boxed: @boxed inner,
// Nested structs will be recursively applied this macro
// `OtherStruct` will be constructed using the same `meta_default_constructor!`
// use another syntax like wrapping it in parenthesis to ignore this
other: OtherStruct {
..
},
// append [..Default::default()] at the end
}
)