Odd problem Create Doc Comments from within a macro

So I have a macro

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> {
            fn expected(&self) -> Expected {

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


1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.