pub unsafe trait AnyLifetime<'a>: 'a {
    fn static_type_id() -> TypeId
    where
        Self: Sized
; fn static_type_of(&self) -> TypeId; }
Expand description

Like Any, but while Any requires 'static, this version allows a lifetime parameter.

Code using this trait is unsafe if your implementation of the inner methods do not meet the invariants listed. Therefore, it is recommended you use one of the helper macros.

If your data type is of the form Foo or Foo<'v> you can derive AnyLifetime:

use gazebo::any::ProvidesStaticType;
#[derive(ProvidesStaticType)]
struct Foo1();
#[derive(ProvidesStaticType)]
struct Foo2<'a>(&'a ());

For more complicated context or constraints, you can implement ProvidesStaticType directly.

use gazebo::any::ProvidesStaticType;
struct Baz<T: Display>(T);
unsafe impl<T> ProvidesStaticType for Baz<T>
    where
        T: ProvidesStaticType + Display,
        T::StaticType: Display + Sized,
{
    type StaticType = Baz<T::StaticType>;
}

Required Methods

Must return the TypeId of Self but where the lifetimes are changed to 'static. Must be consistent with static_type_of.

Must return the TypeId of Self but where the lifetimes are changed to 'static. Must be consistent with static_type_id. Must not consult the self parameter in any way.

Implementations

Is the value of type T.

Downcast a reference to type T, or return None if it is not the right type.

Downcast a mutable reference to type T, or return None if it is not the right type.

Implementors

Any ProvidesStaticType can implement AnyLifetime.

Note ProvidesStaticType and AnyLifetime cannot be the same type, because AnyLifetime need to be object safe, and ProvidesStaticType has type member.