Skip to content

Add a shorter macro for println!("{:?}", foo) #12015

Closed
@SimonSapin

Description

@SimonSapin

When print-debugging, I find myself writing println!("{:?}", some expression) a lot. I wish I didn’t have to write the "{:?}" part, which is always the same. For temporary debugging-only code, I don’t care about making the output pretty, I only want to see what’s going on.

So I’d like to have a new macro added wherever println!() is defined:

macro_rules! dump(
    ($a: expr) => { println!("{:?}", $a) }
    ($a: expr, $b: expr) => { println!("{:?} {:?}", $a, $b) }
    ($a: expr, $b: expr, $c: expr) => { println!("{:?} {:?} {:?}", $a, $b, $c) }
    ($a: expr, $b: expr, $c: expr, $d: expr) => { println!("{:?} {:?} {:?} {:?}", $a, $b, $c, $d) }
)

… with this pattern repeated to however many arguments is appropriate. (Although, worst case, one can always pass a tuple.) Or is there a way to write this completely generic over the number of arguments?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions