What does "type Item = (A::Item, $($B::Item),*);" mean

Im reading source code of Future crate,In join.rs:
type Item = (A::Item, $($B::Item),*);
does it mean Item = A::Item == B::Item == C::Item...
so it means Futures A, B, C... must have same type of Result to join together?

This is a macro expansion, that expands to

type Item = (A::Item, B::Item);
type Item = (A::Item, B::Item, C::Item);
type Item = (A::Item, B::Item, C::Item, D::Item);
type Item = (A::Item, B::Item, C::Item, D::Item, E::Item);

$($inner)* means repeat $($inner)* zero or more times (to exact number of times depends on the input to the macro)

for example,

macro_rules! foo {
    ($($bar:expr),*) => {
        $(println!("{}", $bar);)*
    }
}

fn main() {
    foo!(0, 1, "two", "three");
}

expands to

fn main() {
    println!("{}", 0);
    println!("{}", 1);
    println!("{}", "two");
    println!("{}", "three");
}

https://doc.rust-lang.org/book/ch19-06-macros.html?highlight=macro#macros

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.