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
|
#![feature(concat_idents)]
#![allow(nonstandard_style)]
/// Generate 250 items that all match the query, starting with the longest.
/// Those long items should be dropped from the result set, and the short ones
/// should be shown instead.
macro_rules! generate {
([$($x:ident),+], $y:tt, $z:tt) => {
$(
generate!(@ $x, $y, $z);
)+
};
(@ $x:ident , [$($y:ident),+], $z:tt) => {
pub struct $x;
$(
generate!(@@ $x, $y, $z);
)+
};
(@@ $x:ident , $y:ident, [$($z:ident: $zt:ident),+]) => {
impl $y {
pub fn $x($($z: $zt,)+) {}
}
}
}
pub struct First;
pub struct Second;
pub struct Third;
pub struct Fourth;
pub struct Fifth;
generate!(
[a, b, c, d, e],
[a, b, c, d, e, f, g, h, i, j],
[a: First, b: Second, c: Third, d: Fourth, e: Fifth]
);
generate!(
[f, g, h, i, j],
[a, b, c, d, e, f, g, h, i, j],
[a: First, b: Second, c: Third, d: Fourth]
);
generate!(
[k, l, m, n, o],
[a, b, c, d, e, f, g, h, i, j],
[a: First, b: Second, c: Third]
);
generate!(
// reverse it, just to make sure they're alphabetized
// in the result set when all else is equal
[t, s, r, q, p],
[a, b, c, d, e, f, g, h, i, j],
[a: First, b: Second]
);
generate!(
[u, v, w, x, y],
[a, b, c, d, e, f, g, h, i, j],
[a: First]
);
|