Diffstat (limited to 'src/any/static_wrapper.rs')
| -rw-r--r-- | src/any/static_wrapper.rs | 132 |
1 files changed, 76 insertions, 56 deletions
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs index 3d9d057..035b5da 100644 --- a/src/any/static_wrapper.rs +++ b/src/any/static_wrapper.rs @@ -1,6 +1,6 @@ //! Wrapper types that impl [`TypeName`] when their generic type `T` is `'static`. -use crate::{higher_ranked_type, hkt::Marker}; +use crate::hkt::Marker; use super::*; @@ -9,16 +9,18 @@ use super::*; #[repr(transparent)] pub struct OwnedStatic<T: ?Sized>(pub T); -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where { - T: ?Sized + Send + Sync + 'static - }; +impl<'a, 'ctx, T> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for OwnedStatic<T> +where + T: 'static + Send + Sync, +{ + type T = OwnedStatic<T>; +} - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> for OwnedStatic<T> +where + T: 'static + Send + Sync, +{ + type Higher = OwnedStatic<T>; } /// Borrowed static `T` for `'ctx`. @@ -28,16 +30,19 @@ pub struct BorrowedStatic<'ctx, T: ?Sized>(pub &'ctx T); pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>); -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for BorrowedStaticHrt<T> = BorrowedStatic<'ctx, T> where { - T: ?Sized + Send + Sync + 'static - }; +impl<'a, 'ctx, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for BorrowedStaticHrt<T> +where + T: 'static + Send + Sync, +{ + type T = BorrowedStatic<'ctx, T>; +} - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedStatic<'ctx, T> = BorrowedStaticHrt<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> + for BorrowedStatic<'ctx, T> +where + T: 'static + Send + Sync, +{ + type Higher = BorrowedStaticHrt<T>; } /// Borrowed static `T` for `'a`. @@ -47,16 +52,20 @@ pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T); pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>); -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for TempBorrowedStaticHrt<T> = TempBorrowedStatic<'a, T> where { - T: ?Sized + Send + Sync + 'static - }; +impl<'a, 'ctx, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> + for TempBorrowedStaticHrt<T> +where + T: 'static + Send + Sync, +{ + type T = TempBorrowedStatic<'a, T>; +} - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedStatic<'a, T> = TempBorrowedStaticHrt<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> + for TempBorrowedStatic<'a, T> +where + T: 'static + Send + Sync, +{ + type Higher = TempBorrowedStaticHrt<T>; } /// Mutably borrowed static `T` for `'ctx`. @@ -66,16 +75,20 @@ pub struct BorrowedMutStatic<'ctx, T: ?Sized>(pub &'ctx mut T); pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>); -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for BorrowedMutStaticHrt<T> = BorrowedMutStatic<'ctx, T> where { - T: ?Sized + Send + Sync + 'static - }; +impl<'a, 'ctx, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> + for BorrowedMutStaticHrt<T> +where + T: 'static + Send + Sync, +{ + type T = BorrowedMutStatic<'ctx, T>; +} - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedMutStatic<'ctx, T> = BorrowedMutStaticHrt<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> + for BorrowedMutStatic<'ctx, T> +where + T: 'static + Send + Sync, +{ + type Higher = BorrowedMutStaticHrt<T>; } /// Mutably borrowed static `T` for `'a`. @@ -85,16 +98,20 @@ pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T); pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>); -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for TempBorrowedMutStaticHrt<T> = TempBorrowedMutStatic<'a, T> where { - T: ?Sized + Send + Sync + 'static - }; +impl<'a, 'ctx, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> + for TempBorrowedMutStaticHrt<T> +where + T: 'static + Send + Sync, +{ + type T = TempBorrowedMutStatic<'a, T>; +} - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedMutStatic<'a, T> = TempBorrowedMutStaticHrt<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> + for TempBorrowedMutStatic<'a, T> +where + T: 'static + Send + Sync, +{ + type Higher = TempBorrowedMutStaticHrt<T>; } /// Boxed static `T`. @@ -103,16 +120,19 @@ higher_ranked_type! { pub struct BoxedStatic<T: ?Sized>(pub Box<T>); #[cfg(feature = "alloc")] -higher_ranked_type! { - impl TypeName { - impl['a, 'ctx, T] type T['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where { - T: ?Sized + Send + Sync + 'static - }; - - impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where { - T: ?Sized + Send + Sync + 'static - }; - } +impl<'a, 'ctx, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for BoxedStatic<T> +where + T: 'static + Send + Sync, +{ + type T = BoxedStatic<T>; +} + +#[cfg(feature = "alloc")] +impl<'a, 'ctx, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> for BoxedStatic<T> +where + T: 'static + Send + Sync, +{ + type Higher = BoxedStatic<T>; } #[cfg(test)] |