use disjoint_impls::disjoint_impls; pub trait Dispatch { type Group; } pub enum GroupA {} impl Dispatch for String { type Group = GroupA; } impl Dispatch for Vec { type Group = GroupA; } pub enum GroupB {} impl Dispatch for i32 { type Group = GroupB; } impl Dispatch for u32 { type Group = GroupB; } disjoint_impls! { pub trait Kita { const NAME: &'static str; fn name() -> &'static str { "Default blanket" } } impl> Kita for T { const NAME: &'static str = "Blanket A"; } impl> Kita for U { const NAME: &'static str = "Blanket B"; fn name() -> &'static str { "Blanket B" } } } /* pub trait Kita { const NAME: &'static str; fn name() -> &'static str { "Default blanket" } } const _: () = { pub trait _Kita0<_0: ?Sized> { const NAME: &'static str; fn name() -> &'static str { "Default blanket" } } impl<_0: Dispatch> _Kita0 for _0 { const NAME: &'static str = "Blanket A"; } impl<_0: Dispatch> _Kita0 for _0 { const NAME: &'static str = "Blanket B"; fn name() -> &'static str { "Blanket B" } } impl<_0> Kita for _0 where _0: Dispatch, Self: _Kita0<<_0 as Dispatch>::Group> { const NAME: &'static str = ::Group>>::NAME; fn name() -> &'static str { ::Group>>::name() } } }; */ #[test] fn basic() { assert_eq!("Blanket A", String::NAME); assert_eq!("Blanket A", Vec::::NAME); assert_eq!("Blanket B", u32::NAME); assert_eq!("Blanket B", i32::NAME); assert_eq!("Default blanket", String::name()); assert_eq!("Default blanket", Vec::::name()); assert_eq!("Blanket B", u32::name()); assert_eq!("Blanket B", i32::name()); }