use disjoint_impls::disjoint_impls;
pub trait Dispatch1 {
type Group;
}
pub trait Dispatch2 {
type Group;
}
pub trait Dispatch3 {
type Group;
}
pub enum GroupA {}
pub enum GroupB {}
impl Dispatch1 for String {
type Group = GroupA;
}
impl Dispatch2 for String {
type Group = GroupA;
}
impl Dispatch3 for String {
type Group = GroupA;
}
impl Dispatch1 for Vec<u32> {
type Group = GroupA;
}
impl Dispatch2 for Vec<u32> {
type Group = GroupA;
}
impl Dispatch3 for Vec<u32> {
type Group = GroupB;
}
impl Dispatch1 for Vec<i32> {
type Group = GroupA;
}
impl Dispatch2 for Vec<i32> {
type Group = GroupB;
}
impl Dispatch3 for Vec<i32> {
type Group = GroupA;
}
impl Dispatch1 for u32 {
type Group = GroupA;
}
impl Dispatch2 for u32 {
type Group = GroupB;
}
impl Dispatch3 for u32 {
type Group = GroupB;
}
impl Dispatch1 for i32 {
type Group = GroupB;
}
struct Wrapper<T>(T);
disjoint_impls! {
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupA> + Dispatch3<Group = GroupA>> Wrapper<T> {
const NAME: &'static str = "Blanket AAA";
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupA> + Dispatch3<Group = GroupB>> Wrapper<T> {
const NAME: &'static str = "Blanket AAB";
}
impl<T: Dispatch1<Group = GroupA> + Dispatch2<Group = GroupB>> Wrapper<T> {
const NAME: &'static str = "Blanket AB*";
}
impl<T: Dispatch1<Group = GroupB>> Wrapper<T> {
const NAME: &'static str = "Blanket B**";
}
}
#[test]
fn inherent_nested_subgroups() {
assert_eq!("Blanket AAA", Wrapper::<String>::NAME);
assert_eq!("Blanket AAB", Wrapper::<Vec::<u32>>::NAME);
assert_eq!("Blanket AB*", Wrapper::<Vec::<i32>>::NAME);
assert_eq!("Blanket B**", Wrapper::<i32>::NAME);
}