lolad
lolad

Reputation: 321

How do I detect if an optional keyword was supplied to a declarative macro?

I'm writing a macro:

macro_rules! foo {
    ($(print)?) => {
        // run `println!("hello") if print is given
    }
}

Which could be called as:

How do I detect if print was supplied? When I use a repetition operator I need to put a variable in. Is there some sort of empty variable I can use? ((print $print:empty)?)

Upvotes: 2

Views: 432

Answers (0)

Related Questions