macro_rules! meta_default_constructor { ( {$($imports: stmt);* $(;)?} $($tt: tt)* ) => { ... }; ( [$func: expr] ::$($ty: ident)::* $([$($generics: tt)*])? {$($tt: tt)*} ) => { ... }; ( [$func: expr] $($ty: ident)::* $([$($generics: tt)*])? {$($tt: tt)*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: $block: block $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: ::$($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: $($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: box ::$($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: box $($ty2: ident)::* {$($fields: tt)*} $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: box $expr: expr $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$func: expr] [$($ty: tt)*] $([$($generics: tt)*])? {$field: ident: $expr: expr $(, $($tt: tt)*)?} {$($out_field: ident: $out_expr: expr),*} ) => { ... }; ( [$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,
// 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
}
)