1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73#![allow(missing_docs, dead_code)]
use static_assertions::{assert_impl_one, assert_not_impl_any};
use variadics_please::all_tuples;
trait Foo {}
macro_rules! foo {
($($t: ident),* $(,)?) => {
impl<$($t),*> Foo for ($($t,)*) {}
};
}
// [0, 2]
all_tuples!(foo, 0, 2, T);
// no {3}
// [4, 5]
all_tuples!(foo, 4, 5, T);
trait Bar {}
macro_rules! bar {
($(($t1: ident, $t2: ident)),* $(,)?) => {
impl<$($t1,)* $($t2),*> Bar for ($(($t1, $t2),)*) {}
};
}
// [0, 2]
all_tuples!(bar, 0, 2, T, U);
// no {3}
// [4, 5]
all_tuples!(bar, 4, 5, T, U);
#[test]
fn basic_test() {
// 0
assert_impl_one!((): Foo);
// 1
assert_impl_one!(((),): Foo);
// 2
assert_impl_one!(((), ()): Foo);
// no 3
assert_not_impl_any!(((), (), ()): Foo);
// 4
assert_impl_one!(((), (), (), ()): Foo);
// 5
assert_impl_one!(((), (), (), (), ()): Foo);
// no 6
assert_not_impl_any!(((), (), (), (), (), ()): Foo);
// ((T, U), ..)
// 0
assert_impl_one!((): Bar);
// 1
assert_impl_one!((((), ()),): Bar);
// 2
assert_impl_one!((((),()), ((),())): Bar);
// no 3
assert_not_impl_any!((((),()), ((),()), ((),())): Bar);
// 4
assert_impl_one!((((),()), ((),()), ((),()), ((),())): Bar);
// 5
assert_impl_one!((((),()), ((),()), ((),()), ((),()), ((),())): Bar);
// no 6
assert_not_impl_any!((((),()), ((),()), ((),()), ((),()), ((),()), ((),())): Bar);
}