I'm writing a macro:
macro_rules! foo {
($(print)?) => {
// run `println!("hello") if print is given
}
}
Which could be called as:
foo!()
which would do nothingfoo!(print)
which would print hello
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)?
)
Make separate rules for each case:
playground