[][src]Trait traitcast::Traitcast

pub trait Traitcast<To: ?Sized> {
    fn cast_ref(&self) -> Option<&To>;
fn cast_mut(&mut self) -> Option<&mut To>;
fn cast_box(self: Box<Self>) -> Result<Box<To>, Box<dyn Any>>; }

A convenience trait with a blanket implementation that adds methods to cast from any trait that implements TraitcastFrom, to any trait that implements TraitcastTo.

Required methods

fn cast_ref(&self) -> Option<&To>

A convenience method that wraps the top-level cast_ref function.

fn cast_mut(&mut self) -> Option<&mut To>

A convenience method that wraps the top-level cast_mut function.

fn cast_box(self: Box<Self>) -> Result<Box<To>, Box<dyn Any>>

A convenience method that wraps the top-level cast_box function.

Loading content...

Implementors

impl<From: ?Sized, To: ?Sized> Traitcast<To> for From where
    From: TraitcastFrom,
    To: TraitcastTo + 'static, 
[src]

fn cast_ref(&self) -> Option<&To>[src]

Tries to cast self to a different dynamic trait object. This will always return None if the implementation of the target trait, for the concrete type of self, has not been registered via traitcast_to_impl!.

fn cast_mut(&mut self) -> Option<&mut To>[src]

Tries to cast the self to a different dynamic trait object. This will always return None if the implementation of the target trait, for the concrete type of self, has not been registered via traitcast_to_impl!.

fn cast_box(self: Box<Self>) -> Result<Box<To>, Box<dyn Any>>[src]

Tries to cast self to a boxed dynamic trait object. This will always return Err if the implementation of the target trait, for the concrete type of self, has not been registered via traitcast_to_impl!.

Loading content...