Trait Downcast

Source
pub trait Downcast: AsAny {
    // Provided methods
    fn is<T>(&self) -> bool
       where T: AsAny { ... }
    fn downcast_ref<T>(&self) -> Option<&T>
       where T: AsAny { ... }
    fn downcast_mut<T>(&mut self) -> Option<&mut T>
       where T: AsAny { ... }
}
Expand description

This is a shim around AaAny to avoid some boilerplate code. It is a separate trait because it is also implemented on runtime polymorphic traits (which are !Sized).

Provided Methods§

Source

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T.

Forward to the method defined on the type Any.

Source

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.

Source

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: ?Sized + AsAny> Downcast for T