macro_rules! map_addr_version {
    ($addr:ident: $ty:tt; $expr:expr) => { ... };
    ($addr:ident: $ty:tt; $expr_v4:expr, $expr_v6:expr) => { ... };
    (( $( $addr:ident : $ty:tt ),+ ); $match:expr, $mismatch:expr) => { ... };
    (( $( $addr:ident : $ty:tt ),+ ); $match_v4:expr, $match_v6:expr, $mismatch:expr) => { ... };
    (( $( $addr:ident : $ty:tt ),+ ); $match:expr, $mismatch:expr,) => { ... };
}
Expand description

Map an expression over either version of one or more addresses.

map_addr_version! when given a value of a type which is an enum with two variants - V4 and V6 - matches on the variants, and for both variants, invokes an expression on the inner contents. $addr is both the name of the variable to match on, and the name that the address will be bound to for the scope of the expression.

map_addr_version! when given a list of values and their types (all enums with variants V4 and V6), matches on the tuple of values and invokes the $match expression when all values are of the same variant. Otherwise the $mismatch expression is invoked.

To make it concrete, the expression map_addr_version!(bar: Foo; blah(bar)) desugars to:

match bar {
    Foo::V4(bar) => blah(bar),
    Foo::V6(bar) => blah(bar),
}

Also, map_addr_version!((foo: Foo, bar: Bar); blah(foo, bar), unreachable!()) desugars to:

match (foo, bar) {
    (Foo::V4(foo), Bar::V4(bar)) => blah(foo, bar),
    (Foo::V6(foo), Bar::V6(bar)) => blah(foo, bar),
    _ => unreachable!(),
}