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§
Sourcefn downcast_ref(&self) -> Option<&Target>
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.
Sourceunsafe fn downcast_ref_unchecked(&self) -> &Target
Available on crate feature downcast_unchecked only.
unsafe fn downcast_ref_unchecked(&self) -> &Target
downcast_unchecked only.Unchecked variant of downcast_ref
§Safety
This function is unsafe because the caller must ensure that the cast is valid.
Sourcefn downcast_mut(&mut self) -> Option<&mut Target>
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.
Sourceunsafe fn downcast_mut_unchecked(&mut self) -> &mut Target
Available on crate feature downcast_unchecked only.
unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target
downcast_unchecked only.Unchecked variant of downcast_ref
§Safety
This function is unsafe because the caller must ensure that the cast is valid.