Struct TraitcastTarget

Source
pub struct TraitcastTarget { /* private fields */ }
Expand description

A struct representing the transformation from dyn TraitcastableAny to another dyn Trait.

This should generally not be manually used, but generated by the make_trait_castable attribute macro.

Implementations§

Source§

impl TraitcastTarget

Source

pub const fn from<Src: TraitcastableTo<Target>, Target: 'static + ?Sized>() -> Self

Creates a new TraitcastTarget from a TraitcastableTo implementation.

Examples found in repository?
examples/manual_generic_struct.rs (line 66)
65  const TARGETS: &[TraitcastTarget] = &[
66    TraitcastTarget::from::<Self, dyn Dog>(),
67    TraitcastTarget::from::<Self, dyn Cat<str>>(),
68  ];
More examples
Hide additional examples
examples/manual.rs (line 40)
39    const TARGETS: &[TraitcastTarget] = &[
40      TraitcastTarget::from::<HybridPet, dyn Dog>(),
41      TraitcastTarget::from::<HybridPet, dyn Cat>(),
42    ];
Source

pub const fn target_type_id(&self) -> TypeId

Returns the TypeId of the type to which can be cast with this instance.

Auto Trait Implementations§

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> TraitcastableAny for T
where T: 'static,

Source§

default fn traitcast_targets(&self) -> &[TraitcastTarget]

This function returns a list of all the TraitcastTarget’s to which a trait object can be cast, this is then used by the implementations of TraitcastableAnyInfra to accomplish the traitcast. The function is used to generate debug output for TraitcastableAny. The default implementation of find_traitcast_target uses this function by default. Read more
Source§

default fn find_traitcast_target( &self, target: TypeId, ) -> Option<&TraitcastTarget>

This function can be implemented to support custom TypeId lookup algorithms. This may be desired when there are lots of TraitcastTargets (30 or more). Read more
Source§

fn type_id(&self) -> TypeId

Returns the TypeId of the concrete type.
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.