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 Dispatch1 for Vec { type Group = GroupA; } impl Dispatch2 for Vec { 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 + Dispatch2> Kita for T { const NAME: &'static str = "Blanket AA"; } impl + Dispatch2> Kita for T { const NAME: &'static str = "Blanket AB"; } impl + Dispatch2> Kita for T { const NAME: &'static str = "Blanket B*"; } } /* pub trait Kita { const NAME: &'static str; } const _: () = { pub trait _Kita0<_0: ?Sized, _1: ?Sized> { const NAME: &'static str; } impl<_0: Dispatch1 + Dispatch2> _Kita0 for _0 { const NAME: &'static str = "Blanket AA"; } impl<_0: Dispatch1 + Dispatch2> _Kita0 for _0 { const NAME: &'static str = "Blanket AB"; } impl<_0: Dispatch1 + Dispatch2> _Kita0::Group> for _0 { const NAME: &'static str = "Blanket B*"; } impl<_0> Kita for _0 where _0: Dispatch1 + Dispatch2, Self: _Kita0<<_0 as Dispatch1>::Group, <_0 as Dispatch2>::Group> { const NAME: &'static str = ::Group, <_0 as Dispatch2>::Group>>::NAME; } }; */ #[test] fn multiple_dispatch_traits() { assert_eq!("Blanket AA", String::NAME); assert_eq!("Blanket AB", Vec::::NAME); assert_eq!("Blanket B*", u32::NAME); assert_eq!("Blanket B*", i32::NAME); }