pub unsafe trait Tid<'a>: 'a {
    fn self_id(&self) -> TypeId;
    fn id() -> TypeId
    where
        Self: Sized
; }
Expand description

This trait indicates that this type can be converted to trait object with typeid while preserving lifetime information. Extends Any functionality for types with single lifetime

Use it only as a dyn Tid<'a> or as super trait when you need to create trait object. In all other places use TidAble<'a>.

Lifetime here is necessary to make dyn Tid<'a> + 'a invariant over 'a.

Required Methods

Returns type id of the type of self

Note that returned type id is guaranteed to be different from provided by Any. It is necessary for the creation of dyn Tid from dyn Any to be sound.

Returns type id of this type

Implementations

Tries to downcast dyn Tid to T

Use it only if dyn Tid was created from concrete T:Any via From implementations. See examples how it does relate to other downcast methods

struct S;
tid!(S);

let a = &S;
let from_any: &dyn Tid = a.into();
assert!(from_any.downcast_any_ref::<S>().is_some());
assert!(from_any.downcast_ref::<S>().is_none());

let direct = &S as &dyn Tid;
assert!(direct.downcast_any_ref::<S>().is_none());
assert!(direct.downcast_ref::<S>().is_some());

See downcast_any_ref

See downcast_any_ref

Trait Implementations

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Implementors