-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,91 @@ | ||
//use disjoint_impls::disjoint_impls; | ||
// | ||
//pub trait Dispatch { | ||
// type Group; | ||
//} | ||
// | ||
//pub enum GroupA {} | ||
//impl Dispatch for String { | ||
// type Group = GroupA; | ||
//} | ||
//impl<T> Dispatch for Vec<T> { | ||
// type Group = GroupA; | ||
//} | ||
// | ||
//pub enum GroupB {} | ||
//impl Dispatch for i32 { | ||
// type Group = GroupB; | ||
//} | ||
//impl Dispatch for u32 { | ||
// type Group = GroupB; | ||
//} | ||
// | ||
//pub struct Wrapper<'a, T, const N: usize>(&'a T); | ||
// | ||
//disjoint_impls! { | ||
// impl<T> Wrapper<'_, T, 12> where T: Dispatch<Group = GroupA> + Dispatch<Group = GroupA> { | ||
// pub const NAME: &'static str = "1st Blanket A"; | ||
// } | ||
// impl<T> Wrapper<'_, T, 12> where T: Dispatch<Group = GroupB> + Dispatch<Group = GroupB> { | ||
// pub const NAME: &'static str = "1st Blanket B"; | ||
// } | ||
// | ||
// impl<T: Dispatch<Group = GroupA> + Dispatch<Group = GroupA>> Wrapper<'_, T, 14> { | ||
// pub const NAME: &'static str = "2nd Blanket A"; | ||
// } | ||
// impl<T: Dispatch<Group = GroupB> + Dispatch<Group = GroupB>> Wrapper<'_, T, 14> { | ||
// pub const NAME: &'static str = "2nd Blanket B"; | ||
// } | ||
//} | ||
// | ||
// | ||
//const _: () = { | ||
// pub trait _Wrapper0<_0: ?Sized> { | ||
// const NAME: &'static str; | ||
// } | ||
// | ||
// impl<_2> _Wrapper0<GroupA> for Wrapper<'_, _2, 12> where _2: Dispatch<Group = GroupA> + Dispatch<Group = GroupA> { | ||
// const NAME: &'static str = "Blanket A"; | ||
// } | ||
// impl<_2> _Wrapper0<GroupB> for Wrapper<'_, _2, 12> where _2: Dispatch<Group = GroupB> { | ||
// const NAME: &'static str = "Blanket B"; | ||
// } | ||
// | ||
// impl<_2> Wrapper<'_, _2, 12> where _2: Dispatch, Self: _Wrapper0<<_2 as Dispatch>::Group> { | ||
// pub const NAME: &'static str = <Self as _Wrapper0<<_2 as Dispatch>::Group>>::NAME; | ||
// } | ||
//}; | ||
// | ||
// | ||
//#[test] | ||
//fn disjoint_inherent_impl() { | ||
// assert_eq!("Blanket A", <Wrapper<String, 12>>::NAME); | ||
// assert_eq!("Blanket A", <Wrapper<Vec::<u32>, 12>>::NAME); | ||
// assert_eq!("Blanket B", <Wrapper<u32, 14>>::NAME); | ||
// assert_eq!("Blanket B", <Wrapper<i32, 14>>::NAME); | ||
//} | ||
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<T> A for Vec<T> {} | ||
impl<T> Dispatch for Vec<T> { | ||
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<T: A> Wrapper<'_, T, 12> where T: Dispatch<Group = GroupA> + Dispatch<Group = GroupA> { | ||
pub const NAME: &'static str = "1st Blanket A"; | ||
} | ||
impl<T> Wrapper<'_, T, 12> where T: Dispatch<Group = GroupB> + Dispatch<Group = GroupB> + B { | ||
pub const NAME: &'static str = "1st Blanket B"; | ||
} | ||
|
||
impl<T: Dispatch<Group = GroupA> + Dispatch<Group = GroupA>> Wrapper<'_, T, 14> { | ||
pub const NAME: &'static str = "2nd Blanket A"; | ||
} | ||
impl<T: Dispatch<Group = GroupB> + Dispatch<Group = GroupB>> Wrapper<'_, T, 14> { | ||
pub const NAME: &'static str = "2nd Blanket B"; | ||
} | ||
} | ||
|
||
/* | ||
const _: () = { | ||
pub trait _Wrapper0<_0: ?Sized> { | ||
const NAME: &'static str; | ||
} | ||
pub trait _Wrapper1<_0: ?Sized> { | ||
const NAME: &'static str; | ||
} | ||
impl<_0: A> _Wrapper0<GroupA> for Wrapper<'_, _0, 12> where _0: Dispatch<Group = GroupA> + Dispatch<Group = GroupA> { | ||
const NAME: &'static str = "1st Blanket A"; | ||
} | ||
impl<_0> _Wrapper0<GroupB> for Wrapper<'_, _0, 12> where _0: Dispatch<Group = GroupB> + Dispatch<Group = GroupB> + B { | ||
const NAME: &'static str = "1st Blanket B"; | ||
} | ||
impl<_0: Dispatch<Group = GroupA> + Dispatch<Group = GroupA>> _Wrapper1<GroupA> for Wrapper<'_, _0, 14> { | ||
const NAME: &'static str = "2nd Blanket A"; | ||
} | ||
impl<_0: Dispatch<Group = GroupB> + Dispatch<Group = GroupB>> _Wrapper1<GroupB> for Wrapper<'_, _0, 14> { | ||
const NAME: &'static str = "2nd Blanket B"; | ||
} | ||
impl<_0> Wrapper<'_, _0, 12> where _0: Dispatch, Self: _Wrapper0<<_0 as Dispatch>::Group> { | ||
pub const NAME: &'static str = <Self as _Wrapper0<<_0 as Dispatch>::Group>>::NAME; | ||
} | ||
impl<_0> Wrapper<'_, _0, 14> where _0: Dispatch, Self: _Wrapper1<<_0 as Dispatch>::Group> { | ||
pub const NAME: &'static str = <Self as _Wrapper1<<_0 as Dispatch>::Group>>::NAME; | ||
} | ||
}; | ||
*/ | ||
|
||
#[test] | ||
fn disjoint_inherent_impl() { | ||
assert_eq!("1st Blanket A", <Wrapper<String, 12>>::NAME); | ||
assert_eq!("1st Blanket A", <Wrapper<Vec::<u32>, 12>>::NAME); | ||
assert_eq!("1st Blanket B", <Wrapper<u32, 12>>::NAME); | ||
assert_eq!("1st Blanket B", <Wrapper<i32, 12>>::NAME); | ||
|
||
assert_eq!("2nd Blanket A", <Wrapper<String, 14>>::NAME); | ||
assert_eq!("2nd Blanket A", <Wrapper<Vec::<u32>, 14>>::NAME); | ||
assert_eq!("2nd Blanket B", <Wrapper<u32, 14>>::NAME); | ||
assert_eq!("2nd Blanket B", <Wrapper<i32, 14>>::NAME); | ||
} |