pub trait Downcast<T> {
fn can_downcast(&self) -> bool;
fn downcast(self) -> Result<T, Self>
where
Self: Sized;
fn downcast_ref(&self) -> Option<&T>;
unsafe fn downcast_unchecked(self) -> T;
unsafe fn downcast_ref_unchecked(&self) -> &T;
}Expand description
Downcasts support.
Required Methods
sourcefn can_downcast(&self) -> bool
fn can_downcast(&self) -> bool
Checks if it’s possible to downcast to T.
Returns true if the instance implements T and false otherwise.
sourcefn downcast(self) -> Result<T, Self>where
Self: Sized,
fn downcast(self) -> Result<T, Self>where
Self: Sized,
Tries to downcast to T.
Returns Ok(T) if the instance implements T and Err(Self) otherwise.
sourcefn downcast_ref(&self) -> Option<&T>
fn downcast_ref(&self) -> Option<&T>
Tries to downcast to &T.
Returns Some(T) if the instance implements T and None otherwise.
sourceunsafe fn downcast_unchecked(self) -> T
unsafe fn downcast_unchecked(self) -> T
Downcasts to T unconditionally.
Panics if compiled with debug_assertions and the instance doesn’t implement T.
sourceunsafe fn downcast_ref_unchecked(&self) -> &T
unsafe fn downcast_ref_unchecked(&self) -> &T
Downcasts to &T unconditionally.
Panics if compiled with debug_assertions and the instance doesn’t implement T.