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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use disjoint_impls::disjoint_impls;
pub trait Dispatch1 {
type Group;
}
pub trait Dispatch2 {
type Group;
}
pub enum GroupA {}
pub enum GroupB {}
impl Dispatch1 for String {
type Group = GroupA;
}
impl Dispatch2 for String {
type Group = GroupA;
}
impl<T> Dispatch1 for Vec<T> {
type Group = GroupA;
}
impl<T> Dispatch2 for Vec<T> {
type Group = GroupB;
}
impl Dispatch1 for i32 {
type Group = GroupB;
}
impl Dispatch2 for i32 {
type Group = GroupA;
}
impl Dispatch1 for u32 {
type Group = GroupB;
}
impl Dispatch2 for u32 {
type Group = GroupB;
}
disjoint_impls! {
pub trait Kita {
const NAME: &'static str;
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupA>> Kita for T {
const NAME: &'static str = "Blanket AA";
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupB>> Kita for T {
const NAME: &'static str = "Blanket AB";
}
impl<T: Dispatch1<Group = GroupB> + Dispatch2> Kita for T {
const NAME: &'static str = "Blanket B*";
}
}
/*
pub trait Kita {
const NAME: &'static str;
}
const _: () = {
pub trait Kita0<_TŠČ0: ?Sized, _TŠČ1: ?Sized> {
const NAME: &'static str;
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupA>> Kita0<GroupA, GroupA>
for T {
const NAME: &'static str = "Blanket AA";
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupB>> Kita0<GroupA, GroupB>
for T {
const NAME: &'static str = "Blanket AB";
}
impl<T: Dispatch1<Group = GroupB> + Dispatch2> Kita0<GroupB, <T as Dispatch2>::Group>
for T {
const NAME: &'static str = "Blanket B*";
}
impl<_TŠČ0> Kita for _TŠČ0
where
_TŠČ0: Dispatch1,
_TŠČ0: Dispatch2,
Self: Kita0<<_TŠČ0 as Dispatch1>::Group, <_TŠČ0 as Dispatch2>::Group>,
{
const NAME: &'static str = <Self as Kita0<
<_TŠČ0 as Dispatch1>::Group,
<_TŠČ0 as Dispatch2>::Group,
>>::NAME;
}
};
*/
#[test]
fn multiple_dispatch_traits() {
assert_eq!("Blanket AA", String::NAME);
assert_eq!("Blanket AB", Vec::<u32>::NAME);
assert_eq!("Blanket B*", u32::NAME);
assert_eq!("Blanket B*", i32::NAME);
}