Trait DowncastUnchecked

Source
pub trait DowncastUnchecked<'a> {
    type DowncastResult<D: ?Sized + 'a>;

    // Required method
    unsafe fn downcast_unchecked<D: ?Sized + Pointee>(
        self,
        metadata: <D as Pointee>::Metadata,
    ) -> Self::DowncastResult<D>;
}
Expand description

A pointer to an object that can be unsafely downcast to point to another type.

Required Associated Types§

Source

type DowncastResult<D: ?Sized + 'a>

The result of downcasting this pointer to point to the type D. Note that this type need not have the same outer wrapper as the type implementing DowncastUnchecked, since the result of the downcast may involve coercions and dereferences.

Required Methods§

Source

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> Self::DowncastResult<D>

Downcasts this pointer into a new pointer pointing to the same object, but having type D.

Generally, the result of calling this function should be equivalent to turning this pointer type into a raw pointer, removing its metadata, unsafely casting that pointer into a pointer to D using the provided metadata, and then turning that raw pointer into another pointer type.

As long as the concrete type of the pointee matches the concrete type of the metadata provided, then this is guaranteed to result in a pointer which is valid and safe to use.

§Safety

Attaching the provided metadata to a pointer to the same data address as that held by this pointer must be guaranteed to be valid and safe to use before this function can be called.

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<'a, T: ?Sized + 'a> DowncastUnchecked<'a> for Box<T>

Source§

type DowncastResult<D: ?Sized + 'a> = Box<D>

Source§

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> Box<D>

Source§

impl<'a, T: ?Sized + 'a> DowncastUnchecked<'a> for Rc<T>

Source§

type DowncastResult<D: ?Sized + 'a> = Rc<D>

Source§

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> Rc<D>

Source§

impl<'a, T: ?Sized + 'a> DowncastUnchecked<'a> for Arc<T>

Source§

type DowncastResult<D: ?Sized + 'a> = Arc<D>

Source§

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> Arc<D>

Source§

impl<'a, T: ?Sized> DowncastUnchecked<'a> for &'a T

Source§

type DowncastResult<D: ?Sized + 'a> = &'a D

Source§

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> &'a D

Source§

impl<'a, T: ?Sized> DowncastUnchecked<'a> for &'a mut T

Source§

type DowncastResult<D: ?Sized + 'a> = &'a mut D

Source§

unsafe fn downcast_unchecked<D: ?Sized + Pointee>( self, metadata: <D as Pointee>::Metadata, ) -> &'a mut D

Implementors§

Source§

impl<'a, B: ?Sized + DynDynBase, P: DowncastUnchecked<'a> + 'a> DowncastUnchecked<'a> for DynDynFat<B, P>

Source§

impl<'a, B: ?Sized + DynDynBase, T: DynDyn<'a, B> + StableDeref + 'a> DowncastUnchecked<'a> for DynDynRef<'a, B, T>
where T::Target: Unsize<B>,

Source§

impl<'a, B: ?Sized + DynDynBase, T: DynDyn<'a, B> + StableDeref + DerefMut + 'a> DowncastUnchecked<'a> for DynDynRefMut<'a, B, T>
where T::Target: Unsize<B>,