Skip to content

Chapter 17.3 DSL: Curly braces in macro invocation #1956

Open

Description

@Feliksas

in this code snippet

macro_rules! calculate {
    (eval $e:expr) => {
        {
            let val: usize = $e; // Force types to be unsigned integers
            println!("{} = {}", stringify!{$e}, val);
        }
    };
}

what is the implication of using curly braces with stringify! ? Looks like those do not change program behaviour in any way, compared to normal parentheses.

Activity

  1. Kivooeo commented on Sep 9, 2025

    @Kivooeo
    Member

    You can use any braces for macros, there is no actual difference

    fn main() {
        let v = vec!(1,2,3);
        let v = vec!{1,2,3};
        let v = vec![1,2,3];
    }

    I'm not sure if we explaning this somewhere, and I also dont know why, just randomly found this

    Does it worth mentioning?

  2. Feliksas commented on Sep 9, 2025

    @Feliksas
    Author

    probably worth mentioning, since it creates an impression of some kind of special case or implied special meaning in the current context

  3. TXyy2023 commented on Oct 18, 2026

    @TXyy2023

    Submitted #2045 with a short explanation of the delimiter choices and statement semicolons. The original example is unchanged, and chapter tests, five language builds/link checks, and compiled delimiter variants pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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