use disjoint_impls::disjoint_impls; pub trait Dispatch { type Group; } pub trait A {} pub trait B {} pub enum GroupA {} impl A for String {} impl Dispatch for String { type Group = GroupA; } impl A for Vec {} impl Dispatch for Vec { type Group = GroupA; } pub enum GroupB {} impl B for i32 {} impl Dispatch for i32 { type Group = GroupB; } impl B for u32 {} impl Dispatch for u32 { type Group = GroupB; } pub struct Wrapper<'a, T, const N: usize>(&'a T); disjoint_impls! { impl<'a, T: A, U> Wrapper<'a, (T, U), 12> where T: Dispatch + Dispatch { pub const NAME: &'static str = "1st Blanket A"; fn kita(_a: T, _b: U) -> &'static str where T: 'a, U: 'a { Self::NAME } } impl<'b, T, U> Wrapper<'b, (T, U), 12> where T: Dispatch + Dispatch + B { pub const NAME: &'static str = "1st Blanket B"; fn kita(_a: T, _b: U) -> &'static str where T: 'b, U: 'b { Self::NAME } } impl<'c, T: Dispatch + Dispatch> Wrapper<'c, T, 14> { pub const NAME: &'static str = "2nd Blanket A"; } impl<'c, T: Dispatch + Dispatch> Wrapper<'c, T, 14> { pub const NAME: &'static str = "2nd Blanket B"; } } /* const _: () = { pub trait _Wrapper0<'_0, _3: ?Sized, _1, _2> { const NAME: &'static str; fn kita(_a: _1, _b: _2) -> &'static str where _1: '_0, _2: '_0; } pub trait _Wrapper1<'_0, _2: ?Sized, _1> { const NAME: &'static str; } impl<'_0, _1: A, _2> _Wrapper0<'_0, GroupA, _1, _2> for Wrapper<'_0, (_1, _2), 12> where _1: Dispatch + Dispatch { const NAME: &'static str = "1st Blanket A"; fn kita(_a: _1, _b: _2) -> &'static str where _1: '_0, _2: '_0 { Self::NAME } } impl<'_0, _1, _2> _Wrapper0<'_0, GroupB, _1, _2> for Wrapper<'_0, (_1, _2), 12> where _1: Dispatch + Dispatch + B { const NAME: &'static str = "1st Blanket B"; fn kita(_a: _1, _b: _2) -> &'static str where _1: '_0, _2: '_0 { Self::NAME } } impl<'_0, _1: Dispatch + Dispatch> _Wrapper1<'_0, GroupA, _1> for Wrapper<'_0, _1, 14> { const NAME: &'static str = "2nd Blanket A"; } impl<'_0, _1: Dispatch + Dispatch> _Wrapper1<'_0, GroupB, _1> for Wrapper<'_0, _1, 14> { const NAME: &'static str = "2nd Blanket B"; } impl<'_0, _1, _2> Wrapper<'_0, (_1, _2), 12> where _1: Dispatch, Self: _Wrapper0<'_0, <_1 as Dispatch>::Group, _1, _2> { pub const NAME: &'static str = ::Group, _1, _2>>::NAME; fn kita(_a: _1, _b: _2) -> &'static str where _1: '_0, _2: '_0 { ::Group, _1, _2>>::kita(_a, _b) } } impl<'_0, _1> Wrapper<'_0, _1, 14> where _1: Dispatch, Self: _Wrapper1<'_0, <_1 as Dispatch>::Group, _1> { pub const NAME: &'static str = ::Group, _1>>::NAME; } }; */ #[test] fn disjoint_inherent_impl() { assert_eq!("1st Blanket A", >::NAME); assert_eq!("1st Blanket A", , u32), 12>>::NAME); assert_eq!("1st Blanket B", >::NAME); assert_eq!("1st Blanket B", >::NAME); assert_eq!("2nd Blanket A", >::NAME); assert_eq!("2nd Blanket A", , 14>>::NAME); assert_eq!("2nd Blanket B", >::NAME); assert_eq!("2nd Blanket B", >::NAME); assert_eq!( "1st Blanket A", >::kita(String::new(), 12) ); assert_eq!( "1st Blanket A", , u32), 12>>::kita(vec![], 12) ); assert_eq!("1st Blanket B", >::kita(12, 12)); assert_eq!("1st Blanket B", >::kita(12, 12)); }