pub unsafe trait Tid<'a>: 'a {
// Required methods
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§
Implementations§
Source§impl<'a> dyn Tid<'a> + 'a
impl<'a> dyn Tid<'a> + 'a
Sourcepub fn downcast_any_ref<T: Any>(&self) -> Option<&T>
pub fn downcast_any_ref<T: Any>(&self) -> Option<&T>
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());
Sourcepub fn downcast_any_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn downcast_any_mut<T: Any>(&mut self) -> Option<&mut T>
See downcast_any_ref