Diffstat (limited to 'src/any.rs')
| -rw-r--r-- | src/any.rs | 51 |
1 files changed, 34 insertions, 17 deletions
@@ -9,7 +9,10 @@ mod type_name_id; use crate::hkt::{Invariant, Marker}; use core::marker::PhantomData; -use effectful::{bound::IsSync, environment::{DynBind, EnvConfig, Environment, InEnvironment}}; +use effectful::{ + bound::IsSync, + environment::{DynBind, EnvConfig, Environment, InEnvironment}, +}; pub use static_wrapper::*; pub use type_name_id::*; @@ -28,7 +31,10 @@ pub mod TypeName { type T: ?Sized + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx (), Higher = Self>; } - pub trait MemberType<E: EnvConfig>: 'static + for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> {} + pub trait MemberType<E: EnvConfig>: + 'static + for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> + { + } impl<T: ?Sized, E: EnvConfig> MemberType<E> for T where T: 'static + for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -36,10 +42,13 @@ pub mod TypeName { } pub trait LowerTypeWithBound<'a, 'ctx: 'a, E: EnvConfig, B>: 'a + DynBind<E> { - type Higher: ?Sized + MemberTypeForLt<'a, 'ctx, E, &'a &'ctx (), T = Self> /* + MemberType<E>*/; + type Higher: ?Sized + MemberTypeForLt<'a, 'ctx, E, &'a &'ctx (), T = Self> + 'static; } - pub trait LowerType<'a, 'ctx: 'a, E: EnvConfig>: LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> {} + pub trait LowerType<'a, 'ctx: 'a, E: EnvConfig>: + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> + { + } impl<'a, 'ctx: 'a, T: ?Sized, E: EnvConfig> LowerType<'a, 'ctx, E> for T where T: LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> @@ -53,7 +62,8 @@ pub mod TypeName { pub struct RefHrt<T: ?Sized>(Marker<T>); -impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> for RefHrt<T> +impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> + for RefHrt<T> where T: TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B>, <T as TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B>>::T: IsSync<E::NeedSend>, @@ -61,7 +71,8 @@ where type T = &'a <T as TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B>>::T; } -impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B> for &'a T +impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B> + for &'a T where T: TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B>, T: IsSync<E::NeedSend>, @@ -71,14 +82,16 @@ where pub struct MutHrt<T: ?Sized>(Marker<T>); -impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> for MutHrt<T> +impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> + for MutHrt<T> where T: TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B>, { type T = &'a mut <T as TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B>>::T; } -impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B> for &'a mut T +impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B> + for &'a mut T where T: TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B>, { @@ -86,7 +99,8 @@ where } #[cfg(feature = "alloc")] -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for Box<T> +impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> + for Box<T> where T: TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>, { @@ -94,7 +108,8 @@ where } #[cfg(feature = "alloc")] -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for Box<T> +impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> + for Box<T> where T: TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>, { @@ -404,7 +419,9 @@ impl<'a, 'ctx, I: Indirect<'a>, E: EnvConfig> AnyTraitObject<'a, 'ctx, I, E> { /// /// If the type of the stored value is different, then `self` is /// returned as is. - pub fn downcast<T: ?Sized + TypeName::LowerType<'a, 'ctx, E>>(self) -> Result<I::ForT<T>, Self> { + pub fn downcast<T: ?Sized + TypeName::LowerType<'a, 'ctx, E>>( + self, + ) -> Result<I::ForT<T>, Self> { if self.id() == TypeNameId::of_lower::<T, E>() { // SAFETY: We know that the type name type is unique per T because it is bijective. // A self is only made in Self::new where the info is taken from T. @@ -485,20 +502,20 @@ mod test { // The following makes sure that a U could never become a T by the raise then lower process. // This proves that the bijective type names are really bijective. - fn _is_bijective_raise<'a, 'ctx: 'a, T>( - x: &TypeName::T<'a, 'ctx, TypeName::HigherRanked<'a, 'ctx, T>>, + fn _is_bijective_raise<'a, 'ctx: 'a, T, E: Environment>( + x: &TypeName::T<'a, 'ctx, TypeName::HigherRanked<'a, 'ctx, T, E>, E>, ) where - T: TypeName::LowerType<'a, 'ctx>, + T: TypeName::LowerType<'a, 'ctx, E>, { // If C -> B -> A -> B -> C (shown by this assignment), then C and A must be bijective. let _y: &T = x; } // This proves that the bijective type names are really bijective. - fn _is_bijective_lower<'a, 'ctx: 'a, U>( - x: &TypeName::HigherRanked<'a, 'ctx, TypeName::T<'a, 'ctx, U>>, + fn _is_bijective_lower<'a, 'ctx: 'a, U, E: Environment>( + x: &TypeName::HigherRanked<'a, 'ctx, TypeName::T<'a, 'ctx, U, E>, E>, ) where - U: TypeName::MemberType, + U: TypeName::MemberType<E>, { // If A -> B -> C -> B -> A (shown by this assignment), then A and C must be bijective. let _y: &U = x; |