Trait TraitcastableAnyInfraExt

Source
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§

Source

type Output

The type that will be returned on a successful cast. Something like Box<Target>.

Required Methods§

Source

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.

Source

unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate feature 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.

Implementations on Foreign Types§

Source§

impl<Src: TraitcastableAnyInfra<Target> + Send + Sync, Target: Sized + 'static + Send + Sync> TraitcastableAnyInfraExt<Target> for Arc<Src>

Source§

fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.
Source§

impl<Src: TraitcastableAnyInfra<Target> + ?Sized + Send + Sync, Target: ?Sized + 'static + Send + Sync> TraitcastableAnyInfraExt<Target> for Arc<Src>

Source§

type Output = Arc<Target>

Available on crate feature alloc only.
Source§

default fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

default unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.
Source§

impl<Src: TraitcastableAnyInfra<Target> + ?Sized, Target: ?Sized + 'static> TraitcastableAnyInfraExt<Target> for Box<Src>

Source§

type Output = Box<Target>

Available on crate feature alloc only.
Source§

default fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

default unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.
Source§

impl<Src: TraitcastableAnyInfra<Target> + ?Sized, Target: ?Sized + 'static> TraitcastableAnyInfraExt<Target> for Rc<Src>

Source§

type Output = Rc<Target>

Available on crate feature alloc only.
Source§

default fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

default unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.
Source§

impl<Src: TraitcastableAnyInfra<Target>, Target: Sized + 'static> TraitcastableAnyInfraExt<Target> for Box<Src>

Source§

fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.
Source§

impl<Src: TraitcastableAnyInfra<Target>, Target: Sized + 'static> TraitcastableAnyInfraExt<Target> for Rc<Src>

Source§

fn downcast(self) -> Result<Self::Output, Self>

Available on crate feature alloc only.
Source§

unsafe fn downcast_unchecked(self) -> Self::Output

Available on crate features alloc and downcast_unchecked only.

Implementors§