pub trait Downcast {
// Required methods
fn type_id(&self) -> TypeId;
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T;
}
Expand description
Methods for downcasting from an Any
-like trait object.
This should only be implemented on trait objects for subtraits of Any
, though you can
implement it for other types and it’ll work fine, so long as your implementation is correct.
Required Methods§
Sourceunsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T
Downcast from &Any
to &T
, without checking the type matches.
§Safety
The caller must ensure that T
matches the trait object, on pain of undefined behaviour.
Sourceunsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T
Downcast from &mut Any
to &mut T
, without checking the type matches.
§Safety
The caller must ensure that T
matches the trait object, on pain of undefined behaviour.
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.