pub trait TraitcastableAnyInfraExt<Target: ?Sized + 'static>: Sized {
type Output;
// Required methods
fn downcast(self) -> Result<Self::Output, Self>;
unsafe fn downcast_unchecked(self) -> Self::Output;
}
Available on crate feature
alloc
only.Expand description
Extension Trait to implement over Smart Pointer Types (Box
, Rc
, Arc
).
Tries to mimic the API of Any
but additionally allows downcasts to select trait objects.
Required Associated Types§
Required Methods§
Sourcefn downcast(self) -> Result<Self::Output, Self>
fn downcast(self) -> Result<Self::Output, Self>
Same as downcast_ref
and downcast_mut
, except that it downcasts a Box
in place.
Returns None
if the concrete type of self is not Target
and a traitcast is not possible.
§Errors
In case a cast is impossible the original input is returned as the error type. Otherwise the box would be dropped.
Sourceunsafe fn downcast_unchecked(self) -> Self::Output
Available on crate feature downcast_unchecked
only.
unsafe fn downcast_unchecked(self) -> Self::Output
downcast_unchecked
only.Unchecked variant of downcast
§Safety
This function is unsafe because the caller must ensure that the cast is valid.
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.