pub trait AnyExt: Any {
    fn downcast_ref<T: Any>(this: &Self) -> Option<&T> { ... }
    fn downcast_mut<T: Any>(this: &mut Self) -> Option<&mut T> { ... }
    fn downcast_rc<T: Any>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>> { ... }
    fn downcast_arc<T: Any>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>> { ... }
    fn downcast_box<T: Any>(this: Box<Self>) -> Result<Box<T>, Box<Self>> { ... }
    fn downcast_move<T: Any>(this: Self) -> Option<T>
    where
        Self: Sized
, { ... } }
Expand description

Methods here are implemented as an associated functions because otherwise for one they will conflict with methods defined on dyn Any in stdlib, for two they will be available on almost every type in the program causing confusing bugs and error messages For example if you have &Box<dyn Any> and call downcast_ref, instead of failing or working on coerced &dyn Any it would work with type id of Box<dyn Any> itself instead of the type behind dyn Any.

Provided Methods

Attempts to downcast this to T behind reference

Attempts to downcast this to T behind mutable reference

Attempts to downcast this to T behind Rc pointer

Attempts to downcast this to T behind Arc pointer

Attempts to downcast this to T behind Box pointer

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

Implementors