You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a macro that intended to define a public static method in an implementation. However, the pub modifier is essentially ignored. First, it's apparently not allowed within the macro definition, and then it's ignored if I put it outside and before the macro call:
mod m {macro_rules! render_function {($name:ident) => (fn $name(output: &muti32, input: &i32) -> i32{5i32});}structS;implS{fnx(){}pubrender_function!(test);}}fnmain(){let x = m::S::test(&mut3,&4);}
<anon>:20:13: 20:23 error: static method `test` is private
<anon>:20 let x = m::S::test(&mut 3, &4);
For completeness I should state what is probably already obvious, that as a workaround I ended up having to contain an entire impl within the macro definition which itself contained the function definition, like this:
If I change this to define a function in a module (instead of in a struct impl), it does allow me to put pub before the fn within the macro definition and it isn't ignored, whereas, as I said in the first post, if I put pub fn in the macro definition and then call the macro inside the struct impl, it would complain about a syntax error.
I created a macro that intended to define a public static method in an implementation. However, the
pub
modifier is essentially ignored. First, it's apparently not allowed within the macro definition, and then it's ignored if I put it outside and before the macro call:playpen
The text was updated successfully, but these errors were encountered: