pub trait TidExt<'a>: Tid<'a> {
    fn is<T: Tid<'a>>(&self) -> bool { ... }
    fn downcast_ref<'b, T: Tid<'a>>(&'b self) -> Option<&'b T> { ... }
    fn downcast_mut<'b, T: Tid<'a>>(&'b mut self) -> Option<&'b mut T> { ... }
    fn downcast_rc<T: Tid<'a>>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>> { ... }
    fn downcast_arc<T: Tid<'a>>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>> { ... }
    fn downcast_box<T: Tid<'a>>(self: Box<Self>) -> Result<Box<T>, Box<Self>> { ... }
    fn downcast_move<T: Tid<'a>>(self) -> Option<T>
    where
        Self: Sized
, { ... } }
Expand description

Extension trait that contains actual downcasting methods.

Use methods from this trait only if dyn Tid was created directly from T for this particular T

If Self is Sized then any of those calls is optimized to no-op because both T and Self are known statically. Useful if you have generic code that you want to behave differently depending on which concrete type replaces type parameter. Usually there are better ways to do this like specialization, but sometimes it can be the only way.

Provided Methods

Returns true if type behind self is equal to the type of T.

Attempts to downcast self to T behind reference

Attempts to downcast self to T behind mutable reference

Attempts to downcast self to T behind Rc pointer

Attempts to downcast self to T behind Arc pointer

Attempts to downcast self to T behind Box pointer

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization

Implementors