Diffstat (limited to 'src/any.rs')
-rw-r--r--src/any.rs53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/any.rs b/src/any.rs
index 3207f02..411f660 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -6,7 +6,10 @@ pub mod indirect;
mod static_wrapper;
mod type_name_id;
-use crate::{higher_ranked_trait, higher_ranked_type, hkt::{Invariant, Marker}};
+use crate::{
+ higher_ranked_trait, higher_ranked_type,
+ hkt::{Invariant, Marker},
+};
use core::marker::PhantomData;
pub use static_wrapper::*;
@@ -19,11 +22,11 @@ higher_ranked_trait! {
pub type class TypeName for<'a, 'ctx> {
type Bound = &'a &'ctx ();
- type T: { } where {
+ type T: { Send + Sync + 'a } where {
'ctx: 'a
};
- type HigherRanked: { 'static };
+ type HigherRanked: { Send + Sync + 'static };
}
}
@@ -31,14 +34,14 @@ pub struct RefHrt<T: ?Sized>(Marker<T>);
higher_ranked_type! {
impl TypeName {
- impl['a, 'ctx, T] type T['a, 'ctx] for RefHrt<T> =
- &'a TypeName::T<'a, 'ctx, T>
+ impl['a, 'ctx, T] type T['a, 'ctx] for RefHrt<T> =
+ &'a TypeName::T<'a, 'ctx, T>
where {
T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
TypeName::T<'a, 'ctx, T>: 'a
};
- impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a T =
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a T =
RefHrt<TypeName::HigherRanked<'a, 'ctx, T>>
where {
T: ?Sized + TypeName::LowerType<'a, 'ctx>
@@ -50,14 +53,14 @@ pub struct MutHrt<T: ?Sized>(Marker<T>);
higher_ranked_type! {
impl TypeName {
- impl['a, 'ctx, T] type T['a, 'ctx] for MutHrt<T> =
- &'a mut TypeName::T<'a, 'ctx, T>
+ impl['a, 'ctx, T] type T['a, 'ctx] for MutHrt<T> =
+ &'a mut TypeName::T<'a, 'ctx, T>
where {
T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
TypeName::T<'a, 'ctx, T>: 'a
};
- impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a mut T =
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a mut T =
MutHrt<TypeName::HigherRanked<'a, 'ctx, T>>
where {
T: ?Sized + TypeName::LowerType<'a, 'ctx>
@@ -68,13 +71,13 @@ higher_ranked_type! {
#[cfg(feature = "alloc")]
higher_ranked_type! {
impl TypeName {
- impl['a, 'ctx, T] type T['a, 'ctx] for Box<T> =
+ impl['a, 'ctx, T] type T['a, 'ctx] for Box<T> =
Box<TypeName::T<'a, 'ctx, T>>
where {
T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
};
- impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for Box<T> =
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for Box<T> =
Box<TypeName::HigherRanked<'a, 'ctx, T>>
where {
T: ?Sized + TypeName::LowerType<'a, 'ctx>
@@ -116,9 +119,9 @@ higher_ranked_type! {
/// higher_ranked_type! {
/// impl TypeName {
/// impl['a, 'ctx] type T['a, 'ctx] for DynToNum =
-/// dyn ToNum + 'a;
+/// dyn ToNum + Send + Sync + 'a;
///
-/// impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn ToNum + 'a =
+/// impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn ToNum + Send + Sync + 'a =
/// DynToNum;
/// }
/// }
@@ -344,9 +347,7 @@ impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
///
/// If the type of the stored value is different, then `self` is
/// returned as is.
- pub fn downcast<T: ?Sized + TypeName::LowerType<'a, 'ctx>>(
- self,
- ) -> Result<I::ForT<T>, Self> {
+ pub fn downcast<T: ?Sized + TypeName::LowerType<'a, 'ctx>>(self) -> Result<I::ForT<T>, Self> {
if self.id() == TypeNameId::of_lower::<T>() {
// 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.
@@ -383,9 +384,9 @@ mod test {
higher_ranked_type! {
impl TypeName {
impl['a, 'ctx] type T['a, 'ctx] for DynZ =
- dyn Z<'ctx> + 'a;
+ dyn Z<'ctx> + Send + Sync + 'a;
- impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn Z<'ctx> + 'a =
+ impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn Z<'ctx> + Send + Sync + 'a =
DynZ;
}
}
@@ -406,9 +407,7 @@ mod test {
let z = 42;
let x = X(&z);
- let y = (&x as &(dyn AnyTrait<'_> + Send))
- .upcast::<DynZ>()
- .unwrap();
+ let y = (&x as &(dyn AnyTrait<'_> + Send)).upcast::<DynZ>().unwrap();
assert_eq!(y.get(), 42);
}
@@ -428,11 +427,7 @@ mod test {
// 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>,
- >,
+ x: &TypeName::T<'a, 'ctx, TypeName::HigherRanked<'a, 'ctx, T>>,
) where
T: TypeName::LowerType<'a, 'ctx>,
{
@@ -442,11 +437,7 @@ mod test {
// 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>,
- >,
+ x: &TypeName::HigherRanked<'a, 'ctx, TypeName::T<'a, 'ctx, U>>,
) where
U: TypeName::MemberType,
{