Diffstat (limited to 'src/any/static_wrapper.rs')
| -rw-r--r-- | src/any/static_wrapper.rs | 145 |
1 files changed, 59 insertions, 86 deletions
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs index d8c22db..58d101b 100644 --- a/src/any/static_wrapper.rs +++ b/src/any/static_wrapper.rs @@ -1,5 +1,7 @@ //! Wrapper types that impl [`TypeName`] when their generic type `T` is `'static`. +use crate::{higher_ranked_type, hkt::Marker}; + use super::*; /// Owned static `T`. @@ -7,21 +9,15 @@ use super::*; #[repr(transparent)] pub struct OwnedStatic<T: ?Sized>(pub T); -bijective_higher_ranked_type! { - for['ctx] use OwnedStatic[][T]: WithContextLt['ctx][] - for<'a> - (OwnedStatic<T>) - where { - T: ?Sized + 'ctx, - } -} +higher_ranked_type! { + impl TypeName { + impl['a, 'ctx, T] type T['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where { + T: ?Sized + 'static + }; -bijective_higher_ranked_type! { - use OwnedStatic[][T][]: TypeName[][] - for<'ctx> - (OwnedStatic<T>) - where { - T: ?Sized + 'static + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where { + T: ?Sized + 'static + }; } } @@ -29,21 +25,17 @@ bijective_higher_ranked_type! { #[repr(transparent)] pub struct BorrowedStatic<'ctx, T: ?Sized>(pub &'ctx T); -bijective_higher_ranked_type! { - use BorrowedStatic['ctx][T]: WithContextLt['ctx][] - for<'a> - (BorrowedStatic<'ctx, T>) - where { - T: ?Sized + 'ctx, - } -} +pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>); -bijective_higher_ranked_type! { - pub type [][T][]: TypeName[][] - for<'ctx> - (BorrowedStatic<'ctx, T>) - where { - T: ?Sized + 'static +higher_ranked_type! { + impl TypeName { + impl['a, 'ctx, T] type T['a, 'ctx] for BorrowedStaticHrt<T> = BorrowedStatic<'ctx, T> where { + T: ?Sized + 'static + }; + + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedStatic<'ctx, T> = BorrowedStaticHrt<T> where { + T: ?Sized + 'static + }; } } @@ -51,21 +43,17 @@ bijective_higher_ranked_type! { #[repr(transparent)] pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T); -bijective_higher_ranked_type! { - use TempBorrowedStatic['ctx][T]: WithContextLt['ctx][] - for<'a> - (TempBorrowedStatic<'a, T>) - where { - T: ?Sized + 'ctx, - } -} +pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>); -bijective_higher_ranked_type! { - pub type [][T]: TypeName[][] - for<'ctx> - (TempBorrowedStatic<'ctx, T>) - where { - T: ?Sized + 'static +higher_ranked_type! { + impl TypeName { + impl['a, 'ctx, T] type T['a, 'ctx] for TempBorrowedStaticHrt<T> = TempBorrowedStatic<'a, T> where { + T: ?Sized + 'static + }; + + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedStatic<'a, T> = TempBorrowedStaticHrt<T> where { + T: ?Sized + 'static + }; } } @@ -73,21 +61,17 @@ bijective_higher_ranked_type! { #[repr(transparent)] pub struct BorrowedMutStatic<'ctx, T: ?Sized>(pub &'ctx mut T); -bijective_higher_ranked_type! { - use BorrowedMutStatic['ctx][T]: WithContextLt['ctx][] - for<'a> - (BorrowedMutStatic<'ctx, T>) - where { - T: ?Sized + 'ctx, - } -} +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 + 'static + }; -bijective_higher_ranked_type! { - pub type [][T][]: TypeName[][] - for<'ctx> - (BorrowedMutStatic<'ctx, T>) - where { - T: ?Sized + 'static + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedMutStatic<'ctx, T> = BorrowedMutStaticHrt<T> where { + T: ?Sized + 'static + }; } } @@ -95,21 +79,17 @@ bijective_higher_ranked_type! { #[repr(transparent)] pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T); -bijective_higher_ranked_type! { - use TempBorrowedMutStatic['ctx][T]: WithContextLt['ctx][] - for<'a> - (TempBorrowedMutStatic<'a, T>) - where { - T: ?Sized + 'ctx, - } -} +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 + 'static + }; -bijective_higher_ranked_type! { - pub type[][T][]: TypeName[][] - for<'ctx> - (TempBorrowedMutStatic<'ctx, T>) - where { - T: ?Sized + 'static + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedMutStatic<'a, T> = TempBorrowedMutStaticHrt<T> where { + T: ?Sized + 'static + }; } } @@ -119,22 +99,15 @@ bijective_higher_ranked_type! { pub struct BoxedStatic<T: ?Sized>(pub Box<T>); #[cfg(feature = "alloc")] -bijective_higher_ranked_type! { - for['ctx] use BoxedStatic[][T]: WithContextLt['ctx][] - for<'a> - (BoxedStatic<T>) - where { - T: ?Sized + 'ctx, - } -} - -#[cfg(feature = "alloc")] -bijective_higher_ranked_type! { - use BoxedStatic [][T][]: TypeName[][] - for<'ctx> - (BoxedStatic<T>) - where { - T: ?Sized + 'static +higher_ranked_type! { + impl TypeName { + impl['a, 'ctx, T] type T['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where { + T: ?Sized + 'static + }; + + impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where { + T: ?Sized + 'static + }; } } |