diff --git a/Cargo.lock b/Cargo.lock index a410e22..684956e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,7 +115,7 @@ dependencies = [ [[package]] name = "node_tree_derive" -version = "0.6.0" +version = "0.6.1" dependencies = [ "proc-macro2", "quote", diff --git a/node_tree_derive/Cargo.toml b/node_tree_derive/Cargo.toml index b5c5af2..cee7b65 100644 --- a/node_tree_derive/Cargo.toml +++ b/node_tree_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node_tree_derive" -version = "0.6.0" +version = "0.6.1" edition = "2018" exclude = [ diff --git a/node_tree_derive/src/lib.rs b/node_tree_derive/src/lib.rs index d7ebbae..b41a919 100644 --- a/node_tree_derive/src/lib.rs +++ b/node_tree_derive/src/lib.rs @@ -315,6 +315,7 @@ struct Signal { struct Const { attribs: Vec, + public: bool, declare: syn::ItemConst } @@ -337,6 +338,7 @@ struct Hook { struct Func { attribs: Vec, + public: bool, declare: syn::ItemFn } @@ -376,10 +378,17 @@ impl Parse for Class { // Parse any item attributes. let item_attribs: Vec = input.call(syn::Attribute::parse_outer)?; + // Check if the following statement is publicly visible: + let mut is_public: Option = None; + if input.peek(Token![pub]) { + is_public = Some(input.parse::()?); + } + // Parse a constant: if input.peek(Token![const]) { consts.push(Const { attribs: item_attribs, + public: is_public.is_some(), declare: input.parse()? }); } @@ -388,6 +397,7 @@ impl Parse for Class { else if input.peek(Token![fn]) { funcs.push(Func { attribs: item_attribs, + public: is_public.is_some(), declare: input.parse()? }); } @@ -395,12 +405,6 @@ impl Parse for Class { // Parse a custom statement: else { - // Check if the following statement is publicly visible: - let mut is_public: Option = None; - if input.peek(Token![pub]) { - is_public = Some(input.parse::()?); - } - // Parse a let statement: if input.peek(Token![let]) { input.parse::()?; @@ -581,10 +585,11 @@ pub fn class(input: TokenStream) -> TokenStream { let visibility: TokenStream2 = if public { quote! { pub } } else { TokenStream2::new() }; // Generate the constant fields. - let const_fields = consts.iter().map(|Const { attribs, declare }| { + let const_fields = consts.iter().map(|Const { attribs, public, declare }| { + let visibility: TokenStream2 = if *public { quote! { pub } } else { TokenStream2::new() }; quote! { #(#attribs)* - #declare + #visibility #declare } }); @@ -677,10 +682,11 @@ pub fn class(input: TokenStream) -> TokenStream { }); // Generate the functions. - let func_impls = funcs.iter().map(|Func { attribs, declare }| { + let func_impls = funcs.iter().map(|Func { attribs, public, declare }| { + let visibility: TokenStream2 = if *public { quote! { pub } } else { TokenStream2::new() }; quote! { #(#attribs)* - #declare + #visibility #declare } });