struct True;
struct False;
struct A;
struct B;
macro_rules! equals {
// Match when both types are the same
($type1:ty, $type1:ty) => {
True
};
// Match when types are different
($type1:ty, $type2:ty) => {
False
};
}
// Usage examples
type Result1 = equals!(A, A); // expands to True
type Result2 = equals!(A, B); // expands to False
this doesn't compile:
Compiling playground v0.0.1 (/playground)
error: duplicate matcher binding
--> src/lib.rs:9:26
|
9 | (@internal $type:ty, $type:ty) => {
| -------- ^^^^^^^^ duplicate binding
| |
| previous binding
error: could not compile `playground` (lib) due to 1 previous error
for context, I'd be using this macro internally inside another macro, which would operate on combinations of types, e.g. for A, B, C
generate something effectively like:
impl Foo for A {
type Mask = (True, False, False)
}
impl Foo for B {
type Mask = (False, True, False)
}
impl Foo for C {
type Mask = (False, False, True)
}
I'm at the stage inside the type Mask = $( equals!($this, $that) ),+ but can't figure out how to implement that.