Odd problem Create Doc Comments from within a macro

So I have a macro

#[macro_export]
macro_rules! parser {
    //...
    ($($doc:literal)? ($id:ident -> $ot:ty) $(,)? $x:expr,$exp:expr $(,)?) => {
        ///$($doc)?   << 
        #[derive(Copy, Clone)]
        pub struct $id;
        impl Parser for $id {
            type Out = $ot;
            fn parse<'a>(&self, it: &LCChars<'a>) -> ParseRes<'a, Self::Out> {
                (&$x).parse(it)
            }
            fn expected(&self) -> Expected {
                $exp
            }
        }
    };
}

I want to turn the literal I recieve into comments, so that when cargo doc is run, the struct created has documentation

I'm Putting it behind the /// seems to stop the variable from being read. This isn't surprising, but I can't work out a way around it.

Any ideas?

I think you can use $(#[doc = $doc])? to do that.

1 Like

thanks

1 Like