Use repeating arguments in macro along with non-repeating arguments

Sorry for the bad title. I'm trying to make a macro that prints strings and optionally moves the cursor to a location before printing the string.

macro_rules! put {
    ($($arg:tt)+) => {
    ($x:tt, $y:tt, $($arg:tt)+) => {
        minicurses::mv($x, $y); // function that moves the cursor

This doesn't work, as whenever i try to use the macro with the numbers, it thinks I'm trying to format it with a string literal. Output from cargo clippy:

    Checking testing v0.1.0 (directory)
error: format argument must be a string literal
 --> src/
4 |     put!(1, 1, "hello");
  |          ^
help: you might be missing a string literal to format with
4 |     put!("{} {} {}", 1, 1, "hello");
  |          +++++++++++

How would i fix this?

Try moving the more specific rule to be the first one. Currently any input will match the first rule and thus you get print(1, 1, "hello") and it doesn't ever use the second rule.

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.