diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-07 12:21:12 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-07 12:46:05 +0100 |
| commit | efd1853d069fbd1476e82d015da4d0d04cfaccc0 (patch) | |
| tree | 842b745c134306539d10c61be9485794fe8dc7dc /macros/src | |
| parent | eb951c008beea502042db4a3a0e8d1f8b51f6f52 (diff) | |
Show it!
- New show rule syntax
- Set if syntax
- Removed wrap syntax
Diffstat (limited to 'macros/src')
| -rw-r--r-- | macros/src/lib.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 8e44a8c3..eaa929dc 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -47,6 +47,7 @@ fn expand_node( let mut properties = vec![]; let mut construct = None; let mut set = None; + let mut field = None; for item in std::mem::take(&mut impl_block.items) { match item { @@ -61,6 +62,7 @@ fn expand_node( match method.sig.ident.to_string().as_str() { "construct" => construct = Some(method), "set" => set = Some(method), + "field" => field = Some(method), _ => return Err(Error::new(method.span(), "unexpected method")), } } @@ -81,6 +83,14 @@ fn expand_node( let set = generate_set(&properties, set); + let field = field.unwrap_or_else(|| { + parse_quote! { + fn field(&self, name: &str) -> Option<Value> { + None + } + } + }); + let items: syn::punctuated::Punctuated<Ident, syn::Token![,]> = parse_quote! { #stream }; @@ -115,11 +125,13 @@ fn expand_node( impl<#params> model::Node for #self_ty { #construct #set - #vtable + #field fn id(&self) -> model::NodeId { model::NodeId::of::<Self>() } + + #vtable } #(#key_modules)* |
