Diffstat (limited to 'src/any.rs')
-rw-r--r--src/any.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/any.rs b/src/any.rs
index da0f369..5df514c 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -6,7 +6,7 @@ pub mod indirect;
pub mod static_wrapper;
mod type_name_id;
-use crate::{bijective_higher_ranked_trait, bijective_higher_ranked_type};
+use crate::{bijective_higher_ranked_trait, bijective_higher_ranked_type, hkt::Invariant};
use core::marker::PhantomData;
pub use type_name_id::*;
@@ -118,17 +118,18 @@ bijective_higher_ranked_type! {
/// by `id` if [`AnyTrait`] had every trait as a super bound.
///
/// ```
-/// use treaty::any::{AnyTrait, any_trait, nameable};
+/// use treaty::any::{AnyTrait, any_trait, WithContextLt, TypeName};
+/// use treaty::hkt::bijective_higher_ranked_type;
///
/// // Create a test value.
/// let my_num = MyNum(42);
///
/// // Cast to be a AnyTrait trait object.
/// // Now we don't know the type.
-/// let anything: &dyn AnyTrait<'_> = &my_num;
+/// let anything: &(dyn AnyTrait<'_> + Send) = &my_num;
///
/// // We can still upcast to an impl of ToNum.
-/// let to_num_object: &dyn ToNum = anything.upcast().unwrap();
+/// let to_num_object: &dyn ToNum = anything.upcast::<DynToNum>().unwrap();
///
/// assert_eq!(to_num_object.num(), 42);
///
@@ -139,10 +140,15 @@ bijective_higher_ranked_type! {
/// fn num(&self) -> i32;
/// }
///
+/// bijective_higher_ranked_type! {
+/// for['ctx] type DynToNum[][]: WithContextLt['ctx][]
+/// for<'a> (dyn ToNum + 'a)
+/// }
+///
/// // Make the trait object nameable.
-/// nameable! {
-/// struct Name['a, 'ctx];
-/// impl for dyn ToNum + 'a where { }
+/// bijective_higher_ranked_type! {
+/// type [][]: TypeName[][]
+/// for<'ctx> (DynToNum)
/// }
///
/// // An example struct.
@@ -159,7 +165,7 @@ bijective_higher_ranked_type! {
/// // Here the only trait that can be looked up is ToNum as its the only
/// // one in the list.
/// any_trait! {
-/// impl['a, 'ctx] MyNum = [dyn ToNum + 'a];
+/// impl['ctx] MyNum = [DynToNum]
/// }
/// ```
pub trait AnyTrait<'ctx> {
@@ -346,15 +352,8 @@ pub struct AnyTraitObject<'a, 'ctx: 'a, I: Indirect<'a>> {
/// This is some form of &T where T may be sized or not.
indirect: RawIndirect<'a, I>,
- /// Extra type information for the type system.
- _marker: PhantomData<(
- // Invariant over 'a and 'ctx, the TypeNameId doesn't track lifetimes so we have to do it
- // here.
- // https://doc.rust-lang.org/nomicon/phantom-data.html#table-of-phantomdata-patterns
- fn(&'ctx ()) -> &'ctx (),
- // Not Send or Sync.
- *const (),
- )>,
+ _lifetime: Invariant<'ctx>,
+ _not_send_sync: PhantomData<*const ()>,
}
impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
@@ -368,7 +367,8 @@ impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
Self {
info: TypeNameId::of_lower::<T>,
indirect: RawIndirect::new(indirect),
- _marker: PhantomData,
+ _lifetime: Default::default(),
+ _not_send_sync: PhantomData,
}
}