Diffstat (limited to 'src/any/static_wrapper.rs')
| -rw-r--r-- | src/any/static_wrapper.rs | 250 |
1 files changed, 61 insertions, 189 deletions
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs index b846f81..8971ff7 100644 --- a/src/any/static_wrapper.rs +++ b/src/any/static_wrapper.rs @@ -6,227 +6,99 @@ use crate::hkt::Marker; use super::*; -/// Owned static `T`. +/// Named `T` where `T: 'static`. #[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] pub struct OwnedStatic<T: ?Sized>(pub T); -impl<'a, 'ctx, E: EnvConfig, T> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for OwnedStatic<T> -where - T: 'static, -{ - type T = OwnedStatic<T>; +impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Lower<'lt, 'ctx, &'lt &'ctx ()> for OwnedStatic<T> { + type Lowered = OwnedStatic<T>; } -impl<'a, 'ctx, E: EnvConfig, T> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for OwnedStatic<T> -where - T: 'static, -{ - type Higher = OwnedStatic<T>; +impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Raise<'lt, 'ctx, &'lt &'ctx ()> for OwnedStatic<T> { + type Raised = OwnedStatic<T>; } -/// Borrowed static `T` for `'ctx`. +/// Named `&'ctx T` where` T: 'static`. #[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] pub struct BorrowedStatic<'ctx, T: ?Sized>(pub &'ctx T); -#[derive(SendSync)] -pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>); +const _: () = { + pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>); -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for BorrowedStaticHrt<T> -where - T: 'static, -{ - type T = BorrowedStatic<'ctx, T>; -} + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Lower<'lt, 'ctx, &'lt &'ctx ()> + for BorrowedStaticHrt<T> + { + type Lowered = BorrowedStatic<'ctx, T>; + } -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for BorrowedStatic<'ctx, T> -where - T: 'static, -{ - type Higher = BorrowedStaticHrt<T>; -} + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Raise<'lt, 'ctx, &'lt &'ctx ()> + for BorrowedStatic<'ctx, T> + { + type Raised = BorrowedStaticHrt<T>; + } +}; -/// Borrowed static `T` for `'a`. +/// Named `&'lt T` where` T: 'static`. #[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] -pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T); +pub struct TempBorrowedStatic<'lt, T: ?Sized>(pub &'lt T); -#[derive(SendSync)] -pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>); +const _: () = { + pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>); -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for TempBorrowedStaticHrt<T> -where - T: 'static, -{ - type T = TempBorrowedStatic<'a, T>; -} + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Lower<'lt, 'ctx, &'lt &'ctx ()> + for TempBorrowedStaticHrt<T> + { + type Lowered = TempBorrowedStatic<'lt, T>; + } -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for TempBorrowedStatic<'a, T> -where - T: 'static, -{ - type Higher = TempBorrowedStaticHrt<T>; -} + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Raise<'lt, 'ctx, &'lt &'ctx ()> + for TempBorrowedStatic<'lt, T> + { + type Raised = TempBorrowedStaticHrt<T>; + } +}; -/// Mutably borrowed static `T` for `'ctx`. +/// Named `&'ctx mut T` where` T: 'static`. #[derive(PartialEq, Debug, SendSync)] #[repr(transparent)] pub struct BorrowedMutStatic<'ctx, T: ?Sized>(pub &'ctx mut T); -#[derive(SendSync)] -pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>); +const _: () = { + pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>); -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for BorrowedMutStaticHrt<T> -where - T: 'static, -{ - type T = BorrowedMutStatic<'ctx, T>; -} - -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for BorrowedMutStatic<'ctx, T> -where - T: 'static, -{ - type Higher = BorrowedMutStaticHrt<T>; -} - -/// Mutably borrowed static `T` for `'a`. -#[derive(PartialEq, Debug, SendSync)] -#[repr(transparent)] -pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T); - -#[derive(SendSync)] -pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>); - -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for TempBorrowedMutStaticHrt<T> -where - T: 'static, -{ - type T = TempBorrowedMutStatic<'a, T>; -} - -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for TempBorrowedMutStatic<'a, T> -where - T: 'static, -{ - type Higher = TempBorrowedMutStaticHrt<T>; -} - -/// Boxed static `T`. -#[cfg(feature = "alloc")] -#[derive(SendSync)] -#[repr(transparent)] -pub struct BoxedStatic<T: ?Sized>(pub Box<T>); - -#[cfg(feature = "alloc")] -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for BoxedStatic<T> -where - T: 'static, -{ - type T = BoxedStatic<T>; -} - -#[cfg(feature = "alloc")] -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for BoxedStatic<T> -where - T: 'static, -{ - type Higher = BoxedStatic<T>; -} - -#[cfg(test)] -mod test { - use effectful::{block_on::Spin, blocking::Blocking as Block, bound::No, environment::Cfg}; - - use super::*; - - type Blocking = Block<Cfg<Spin, No, No>>; - - #[test] - fn owned_static_has_type_name() { - let a = TypeNameId::of_value::<_, Blocking>(&OwnedStatic(42_i32)); - let b = TypeNameId::of_value::<_, Blocking>(&OwnedStatic(123_i32)); - let c = TypeNameId::of_value::<_, Blocking>(&OwnedStatic(true)); - - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); - } - - #[test] - fn borrowed_static_has_type_name() { - let a = TypeNameId::of_value::<_, Blocking>(&BorrowedStatic(&42_i32)); - let b = TypeNameId::of_value::<_, Blocking>(&BorrowedStatic(&123_i32)); - let c = TypeNameId::of_value::<_, Blocking>(&BorrowedStatic(&true)); - - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Lower<'lt, 'ctx, &'lt &'ctx ()> + for BorrowedMutStaticHrt<T> + { + type Lowered = BorrowedMutStatic<'ctx, T>; } - #[test] - fn temp_borrowed_static_has_type_name() { - let a = TypeNameId::of_value::<_, Blocking>(&TempBorrowedStatic(&42_i32)); - let b = TypeNameId::of_value::<_, Blocking>(&TempBorrowedStatic(&123_i32)); - let c = TypeNameId::of_value::<_, Blocking>(&TempBorrowedStatic(&true)); - - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); - } - - #[test] - fn borrowed_mut_static_has_type_name() { - let mut a = 42_i32; - let mut b = 123_i32; - let mut c = true; - - let a = TypeNameId::of_value::<_, Blocking>(&BorrowedMutStatic(&mut a)); - let b = TypeNameId::of_value::<_, Blocking>(&BorrowedMutStatic(&mut b)); - let c = TypeNameId::of_value::<_, Blocking>(&BorrowedMutStatic(&mut c)); - - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Raise<'lt, 'ctx, &'lt &'ctx ()> + for BorrowedMutStatic<'ctx, T> + { + type Raised = BorrowedMutStaticHrt<T>; } +}; - #[test] - fn temp_borrowed_mut_static_has_type_name() { - let mut a = 42_i32; - let mut b = 123_i32; - let mut c = true; +/// Named `&'lt mut T` where` T: 'static`. +#[derive(PartialEq, Debug, SendSync)] +#[repr(transparent)] +pub struct TempBorrowedMutStatic<'lt, T: ?Sized>(pub &'lt mut T); - let a = TypeNameId::of_value::<_, Blocking>(&TempBorrowedMutStatic(&mut a)); - let b = TypeNameId::of_value::<_, Blocking>(&TempBorrowedMutStatic(&mut b)); - let c = TypeNameId::of_value::<_, Blocking>(&TempBorrowedMutStatic(&mut c)); +const _: () = { + pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>); - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Lower<'lt, 'ctx, &'lt &'ctx ()> + for TempBorrowedMutStaticHrt<T> + { + type Lowered = TempBorrowedMutStatic<'lt, T>; } - #[test] - #[cfg(feature = "alloc")] - fn boxed_static_has_type_name() { - let a = TypeNameId::of_value::<_, Blocking>(&BoxedStatic(Box::new(42_i32))); - let b = TypeNameId::of_value::<_, Blocking>(&BoxedStatic(Box::new(123_i32))); - let c = TypeNameId::of_value::<_, Blocking>(&BoxedStatic(Box::new(true))); - - assert_eq!(a, b); - assert_ne!(a, c); - assert_ne!(b, c); + impl<'lt, 'ctx, T: ?Sized + 'static> type_name::Raise<'lt, 'ctx, &'lt &'ctx ()> + for TempBorrowedMutStatic<'lt, T> + { + type Raised = TempBorrowedMutStaticHrt<T>; } -} +}; |