Diffstat (limited to 'src/any.rs')
| -rw-r--r-- | src/any.rs | 69 |
1 files changed, 34 insertions, 35 deletions
@@ -8,14 +8,14 @@ //! result in a "double fat pointer"?!, and those don't exist. //! //! This module solves both problems. First, [`LtAny`] is a lifetime containing -//! counterpart to [`Any`][core::any::Any]. [`LtAny`] allows one lifetime which +//! counterpart to [`Any`][core::any::Any]. [`LtAny`] allows one lifetime which //! [`treaty`][crate] uses for the `'ctx` lifetime shared by walkers and visitors. //! Second, [`IndirectLtAny`] is able to type erase a pointer like type even //! if it's a `!Sized` type. This allows for type erasing borrows of trait objects //! like `&dyn Trait`. //! //! For a type to be compatible with this module it needs to implement [`TypeNameable`] -//! to give it a unique [`TypeId`][core::any::TypeId]. This can be done manually +//! to give it a unique [`TypeId`][core::any::TypeId]. This can be done manually //! without unsafe code. However, its recommended to use the provided [`nameable`] //! macro when possible. @@ -33,9 +33,9 @@ use alloc::boxed::Box; /// /// The `'a` lifetime is the lifetime `Self` must outlive. /// The `'lt` lifetime is some arbitrary lifetime `Self` can use in it's definition. -/// +/// /// The [`nameable`] allows implementing this trait and [`TypeName`] with minimal effort. -/// For types that are `'static` they can be wrapped by the included wrappers in +/// For types that are `'static` they can be wrapped by the included wrappers in /// the [`static_wrapper`] module. /// /// This trait is circular with [`TypeName`] on [`Self::Name`]. @@ -63,7 +63,7 @@ pub trait TypeName<'a, 'lt>: 'static { /// Implement [`TypeNameable`] and generate a unique name type. /// -/// ``` +/// ```text /// use treaty::any::{nameable, TypeNameable, TypeName}; /// /// pub struct MyType<T>(pub T); @@ -81,7 +81,7 @@ pub trait TypeName<'a, 'lt>: 'static { /// The first list of generics are what will be passed to the generics of `Name`. /// The second `impl` is for [`TypeName`] in `Name`. The type given after the `where` /// needs to match the type given in the first `impl`. However, in the second impl -/// the `T` is a generic for a name not the generic for the type. That's why +/// the `T` is a generic for a name not the generic for the type. That's why /// `T::Nameable` is used instead of `T`. #[doc(hidden)] #[macro_export] @@ -133,52 +133,52 @@ pub use nameable; nameable! { pub struct Name['a, 'lt, T]; - impl [T::Name] for &'lt T where { - T: TypeNameable<'a, 'lt> + ?Sized, T::Name: Sized, 'lt: 'a + impl [T::Name] for &'lt T where { + T: TypeNameable<'a, 'lt> + ?Sized, 'lt: 'a } - impl [T] where &'lt T::Nameable { - T: TypeName<'a, 'lt>, T::Nameable: 'lt, 'lt: 'a + impl [T] where &'lt T::Nameable { + T: TypeName<'a, 'lt> + ?Sized, T::Nameable: 'lt, 'lt: 'a } } nameable! { pub struct Name['a, 'lt, T]; - impl [T::Name] for &'lt mut T where { - T: TypeNameable<'a, 'lt> + ?Sized, T::Name: Sized, 'lt: 'a + impl [T::Name] for &'lt mut T where { + T: TypeNameable<'a, 'lt> + ?Sized, 'lt: 'a } - impl [T] where &'lt mut T::Nameable { - T: TypeName<'a, 'lt>, T::Nameable: 'lt, 'lt: 'a + impl [T] where &'lt mut T::Nameable { + T: TypeName<'a, 'lt> + ?Sized, T::Nameable: 'lt, 'lt: 'a } } nameable! { pub struct Name['a, 'lt, T]; - impl [T::Name] for *const T where { - T: TypeNameable<'a, 'lt> + ?Sized, T::Name: Sized + impl [T::Name] for *const T where { + T: TypeNameable<'a, 'lt> + ?Sized } - impl [T] where *const T::Nameable { - T: TypeName<'a, 'lt> + impl [T] where *const T::Nameable { + T: TypeName<'a, 'lt> + ?Sized } } nameable! { pub struct Name['a, 'lt, T]; - impl [T::Name] for *mut T where { - T: TypeNameable<'a, 'lt> + ?Sized, T::Name: Sized + impl [T::Name] for *mut T where { + T: TypeNameable<'a, 'lt> + ?Sized } - impl [T] where *mut T::Nameable { - T: TypeName<'a, 'lt> + impl [T] where *mut T::Nameable { + T: TypeName<'a, 'lt> + ?Sized } } #[cfg(feature = "alloc")] nameable! { pub struct Name['a, 'lt, T]; - impl [T::Name] for Box<T> where { - T: TypeNameable<'a, 'lt> + ?Sized, T::Name: Sized + impl [T::Name] for Box<T> where { + T: TypeNameable<'a, 'lt> + ?Sized } - impl [T] where Box<T::Nameable> { - T: TypeName<'a, 'lt> + impl [T] where Box<T::Nameable> { + T: TypeName<'a, 'lt> + ?Sized } } @@ -277,7 +277,7 @@ impl<'a, 'lt> dyn LtAny<'lt> + 'a { /// Dynamic trait lookup. /// -/// This trait allows looking up the trait object form of `self` for a +/// This trait allows looking up the trait object form of `self` for a /// given trait object `id`. This is similar to upcasting to the trait given /// by `id` if [`AnyTrait`] had every trait as a super bound. /// @@ -308,7 +308,7 @@ impl<'a, 'lt> dyn LtAny<'lt> + 'a { /// struct Name['a, 'ctx]; /// impl for dyn ToNum + 'a where { } /// } -/// +/// /// // An example struct. /// struct MyNum(i32); /// @@ -626,9 +626,8 @@ mod test { struct X<'a>(&'a mut i32); nameable! { - ['a, 'lt] - X<'lt> where {'lt: 'a} - X<'lt> where {'lt: 'a} + struct Name['a, 'lt]; + impl for X<'lt> where {'lt: 'a} } #[test] @@ -636,8 +635,8 @@ mod test { trait Z {} nameable! { - ['a, 'ctx] - dyn Z + 'a where {'ctx: 'a} + struct Name['a, 'ctx]; + impl for dyn Z + 'a where {'ctx: 'a} } struct X<T>(T); @@ -658,8 +657,8 @@ mod test { } nameable! { - ['a, 'ctx] - dyn Z + 'a where {'ctx: 'a} + struct Name['a, 'ctx]; + impl for dyn Z + 'a where {'ctx: 'a} } struct X(i32); |