[][src]Trait better_any::Tid

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

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

Returns type id of this type

Loading content...

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

Trait Implementations

impl<'a: 'b, 'b> From<&'b (dyn Any + 'static)> for &'b (dyn Tid<'a> + 'a)[src]

impl<'a: 'b, 'b> From<&'b mut (dyn Any + 'static)> for &'b mut (dyn Tid<'a> + 'a)[src]

impl<'a> TidAble<'a> for dyn Tid<'a> + 'a[src]

type Static = __dynTidaa_should_never_exist

Implementors

impl<'a, T: ?Sized + TidAble<'a>> Tid<'a> for T[src]

Loading content...