Skip to content

Feature: Repeat index in macros #21908

Closed
Closed
@Centril

Description

@Centril

It would be really swell if you could somehow access the index or depth of the current repeat in a macro.

Say if we are repeating with $($x), then $#x would yield the index of the current $x in the sequence.

The $# is really not important, could be anything else really.

For example:

#[macro_export]
macro_rules! letmany {
    ($($x:ident),+) => {
        let $x = $#x;
    };
}

fn main() {
    letmany!(a, b, c);
}

Would expand to:

fn main() {
    let a = 0;
    let b = 1;
    let c = 2;
}

Thoughts?

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