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
use disjoint_impls::disjoint_impls;
trait Dispatch<const N: usize> {
type Group;
}
enum GroupA {}
enum GroupB {}
impl Dispatch<1> for [i32; 1] {
type Group = GroupA;
}
impl Dispatch<2> for [i32; 2] {
type Group = GroupB;
}
disjoint_impls! {
trait Kita<const SIZE: usize> {
const NAME: &'static str;
}
impl<const N: usize> Kita<N> for [i32; N]
where
[i32; N]: Dispatch<N, Group = GroupA>,
{
const NAME: &'static str = "Blanket A";
}
impl<const N: usize> Kita<N> for [i32; N]
where
[i32; N]: Dispatch<N, Group = GroupB>,
{
const NAME: &'static str = "Blanket B";
}
}
/*
trait Kita<const SIZE: usize> {
const NAME: &'static str;
}
const _: () = {
trait Kita0<_TŠČ1: ?core::marker::Sized, const _CŠČ0: usize>: Kita<_CŠČ0> {
const NAME_šč: &'static str;
}
impl<const N: usize> Kita0<GroupA, N> for [i32; N]
where
[i32; N]: Dispatch<N, Group = GroupA>,
{
const NAME_šč: &'static str = "Blanket A";
}
impl<const N: usize> Kita0<GroupB, N> for [i32; N]
where
[i32; N]: Dispatch<N, Group = GroupB>,
{
const NAME_šč: &'static str = "Blanket B";
}
impl<const _CŠČ0: usize> Kita<_CŠČ0> for [i32; _CŠČ0]
where
[i32; _CŠČ0]: Dispatch<_CŠČ0>,
Self: for<'_dšč> Kita0<<[i32; _CŠČ0] as Dispatch<_CŠČ0>>::Group, _CŠČ0>,
{
const NAME: &'static str = <Self as Kita0<
<[i32; _CŠČ0] as Dispatch<_CŠČ0>>::Group,
_CŠČ0,
>>::NAME_šč;
}
};
*/
#[test]
fn trait_with_const_param() {
assert_eq!("Blanket A", <[i32; 1]>::NAME);
assert_eq!("Blanket B", <[i32; 2]>::NAME);
}