Skip to content

Chapter 17.2: undescribed repetition pattern? #1955

@Feliksas

Description

@Feliksas

Code example in chapter 17.2 has the following macro defined:

macro_rules! assert_equal_len {
    // The `tt` (token tree) designator is used for
    // operators and tokens.
    ($a:expr, $b:expr, $func:ident, $op:tt) => {
        assert!($a.len() == $b.len(),
                "{:?}: dimension mismatch: {:?} {:?} {:?}",
                stringify!($func),
                ($a.len(),),
                stringify!($op),
                ($b.len(),));
    };
}

It is unclear why $a.len() and $b.len() are wrapped in parentheses with a trailing comma inside after the expression - looks like it could mean multiple instances (or lack) of an expression, but the context does not seem to allow for that. What is the purpose of that syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions