Trait TraitcastableAnyInfra

Source
pub trait TraitcastableAnyInfra<Target: ?Sized>: 'static {
    // Required methods
    fn is(&self) -> bool;
    fn can_be(&self) -> bool;
    fn downcast_ref(&self) -> Option<&Target>;
    unsafe fn downcast_ref_unchecked(&self) -> &Target;
    fn downcast_mut(&mut self) -> Option<&mut Target>;
    unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target;
}
Expand description

Mimics the API of Any but additionally allows downcasts to select trait objects.

Required Methods§

Source

fn is(&self) -> bool

Returns true if Target is the exact same type as Self.

Source

fn can_be(&self) -> bool

Returns true if Self can be converted to a Target.

Source

fn downcast_ref(&self) -> Option<&Target>

Returns some reference to the inner value if it is downcastable to Target, or None if it isn’t.

If Target is Sized this is forwarded to Any::downcast_ref, otherwise TraitcastableAny::traitcast_targets is used to determine if a traitcast is possible.

Returns None if the concrete type of self is not Target and a traitcast is not possible.

Source

unsafe fn downcast_ref_unchecked(&self) -> &Target

Available on crate feature downcast_unchecked only.

Unchecked variant of downcast_ref

§Safety

This function is unsafe because the caller must ensure that the cast is valid.

Source

fn downcast_mut(&mut self) -> Option<&mut Target>

Returns some mutable reference to the inner value if it is downcastable to Target, or None if it isn’t.

If Target is Sized this is forwarded to Any::downcast_ref, otherwise TraitcastableAny::traitcast_targets is used to determine if a traitcast is possible.

Returns None if the concrete type of self is not Target and a traitcast is not possible.

Source

unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target

Available on crate feature downcast_unchecked only.

Unchecked variant of downcast_ref

§Safety

This function is unsafe because the caller must ensure that the cast is valid.

Implementors§

Source§

impl<Target: Sized + 'static + Send + Sync> TraitcastableAnyInfra<Target> for dyn TraitcastableAny + Send + Sync

Source§

impl<Target: Sized + 'static + Send> TraitcastableAnyInfra<Target> for dyn TraitcastableAny + Send

Source§

impl<Target: Sized + 'static> TraitcastableAnyInfra<Target> for dyn TraitcastableAny

Source§

impl<Target: ?Sized + 'static + Send + Sync> TraitcastableAnyInfra<Target> for dyn TraitcastableAny + Send + Sync

Source§

impl<Target: ?Sized + 'static + Send> TraitcastableAnyInfra<Target> for dyn TraitcastableAny + Send

Source§

impl<Target: ?Sized + 'static> TraitcastableAnyInfra<Target> for dyn TraitcastableAny