stdx::anymap

Trait Downcast

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

source

fn type_id(&self) -> TypeId

Gets the TypeId of self.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Downcast for dyn Any

source§

fn type_id(&self) -> TypeId

source§

unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T

source§

unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T

source§

impl Downcast for dyn Any + Send

source§

fn type_id(&self) -> TypeId

source§

unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T

source§

unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T

source§

impl Downcast for dyn Any + Send + Sync

source§

fn type_id(&self) -> TypeId

source§

unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T

source§

unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T

Implementors§