an empty :vis
doesn't work in trait declaration · Issue #65041 · rust-lang/rust (original) (raw)
I want to create a macro that generate fn
s that use in both impl Item...
and trait TraitName
. In trait
, pub
must be omitted, but in impl SomeStruct
I need pub
, so the macro need a $vis:vis
like this:
macro_rules! create_method { ($vis:vis $name:ident) => { visfnvis fn visfnname(&self) { println!("{}", stringify!($name)); } } }
trait T1 { // This not works create_method!(method_of_t1); }
trait T2 { fn method_of_t2(&self); }
struct Struct;
impl T2 for Struct { // This works create_method!(method_of_t2); }
impl Struct {
// I want this method to be pub
, so the macro need a :vis
// for receiving the visibility keyword like this:
create_method!(pub another_method);
}
Expected result: create_method!(method_of_t1);
in trait T1
should works.
(Edit: a better comment about the :vis
in impl Struct
)