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 { type Item; fn kita() -> Self::Item; } impl> Kita for T { type Item = u32; fn kita() -> u32 { 1 } } impl + Default> Kita for U { type Item = U; fn kita() -> Self::Item { U::default() } } } /* pub trait Kita { type Item; fn kita() -> Self::Item; } const _: () = { pub trait _Kita0<_0: ?Sized> { type Item; fn kita() -> Self::Item; } impl<_0: Dispatch> _Kita0 for _0 { type Item = u32; fn kita() -> u32 { 1 } } impl<_0: Dispatch + Default> _Kita0 for _0 { type Item = _0; fn kita() -> Self::Item { <_0>::default() } } impl<_0> Kita for _0 where _0: Dispatch, Self: _Kita0<<_0 as Dispatch>::Group> { type Item = ::Group>>::Item; fn kita() -> Self::Item { ::Group>>::kita() } } }; */ #[test] fn concrete_assoc_type() { assert_eq!(1, String::kita()); assert_eq!(1, Vec::::kita()); assert_eq!(0, u32::kita()); assert_eq!(0, i32::kita()); }