[−][src]Trait better_any::Tid
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
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
fn self_id(&self) -> TypeId
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.
fn id() -> TypeId where
Self: Sized,
Self: Sized,
Returns type id of this type
Implementations
impl<'a> dyn Tid<'a> + 'a
[src]
pub fn downcast_any_ref<T: Any>(&self) -> Option<&T>
[src]
Tries to downcast Self to T
Use it only if dyn Tid
was created from dyn Any
for this particular T
#[derive(Tid)] struct S; let a = &S as &dyn Any; 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());
pub fn downcast_any_mut<T: Any>(&mut self) -> Option<&mut T>
[src]
Use it only if dyn Tid
was created from dyn Any
for this particular T