Struct CastIntoTrait

Source
pub struct CastIntoTrait<DynTrait: ?Sized> {
    pub map: HashMap<TypeId, ImplEntry<DynTrait>>,
}
Expand description

Provides methods for casting into the target trait object from other trait objects.

Fields§

§map: HashMap<TypeId, ImplEntry<DynTrait>>

Implementations§

Source§

impl<DynTrait: ?Sized> CastIntoTrait<DynTrait>

Source

pub fn new() -> Self

Source§

impl<To: ?Sized + 'static> CastIntoTrait<To>

Source

pub fn from_ref<'a, From>(&self, x: &'a From) -> Option<&'a To>
where From: TraitcastFrom + ?Sized,

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

Source

pub fn from_mut<'a, From>(&self, x: &'a mut From) -> Option<&'a mut To>
where From: TraitcastFrom + ?Sized,

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

Source

pub fn from_box<From>(&self, x: Box<From>) -> Result<Box<To>, Box<dyn Any>>
where From: TraitcastFrom + ?Sized,

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

Trait Implementations§

Source§

impl<DynTrait: ?Sized> FromIterator<ImplEntry<DynTrait>> for CastIntoTrait<DynTrait>

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = ImplEntry<DynTrait>>,

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<DynTrait> Freeze for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

§

impl<DynTrait> RefUnwindSafe for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

§

impl<DynTrait> Send for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

§

impl<DynTrait> Sync for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

§

impl<DynTrait> Unpin for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

§

impl<DynTrait> UnwindSafe for CastIntoTrait<DynTrait>
where DynTrait: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> TraitcastFrom for T
where T: 'static,

Source§

fn as_any_ref(&self) -> &(dyn Any + 'static)

Cast to an immutable reference to a trait object.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Cast to a mutable reference to a trait object.
Source§

fn as_any_box(self: Box<T>) -> Box<dyn Any>

Cast to a boxed reference to a trait object.
Source§

fn type_id(&self) -> TypeId

Get the trait object’s dynamic type id.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Any for T
where T: Any,