Struct Casts

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

Stores known ways to cast from concrete types to trait objects.

Implementations§

Source§

impl Casts

Source

pub unsafe fn add<T, U>(&mut self, cast: fn(*const T) -> *const U)
where T: 'static, U: ?Sized + 'static,

Adds a cast from T to U.

§Safety

The provided function must not do anything except trivially return the pointer that it is given, potentially with a vtable attached.

Source

pub fn find_key(&self, src_type: TypeId, dst_type: TypeId) -> Option<u32>

Looks up an index that can be used to quickly access a cast from the source type to the destination type, via Casts::cast.

Source

pub fn cast<Dst>(&self, key: u32, src: *const ()) -> *const Dst
where Dst: ?Sized + 'static,

Casts the input type-erased pointer into the destination type. The resulting pointer is only safe to dereference if the underlying type behind the src pointer is the right source type for the given cast index.

Source

pub fn get_dst(&self, key: u32) -> TypeId

Looks up the destination type for the given cast.

Source

pub fn get_src(&self, key: u32) -> TypeId

Looks up the source type for the given cast.

Source

pub fn find_keys_by_dst<'a>( &'a self, ty: TypeId, ) -> impl Iterator<Item = (TypeId, u32)> + 'a

Iterates over known casts into the given target type. Items in the returned iterator are (source type, cast key).

Source

pub fn find_keys_by_src<'a>( &'a self, ty: TypeId, ) -> impl Iterator<Item = (TypeId, u32)> + 'a

Iterates over known casts out of the given source type. Items in the returned iterator are (target type, cast key).

Trait Implementations§

Source§

impl Default for Casts

Source§

fn default() -> Casts

Returns the “default value” for a type. Read more
Source§

impl Send for Casts

Source§

impl Sync for Casts

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, 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> Satisfies<Send> for T
where T: Send,

Source§

impl<T> Satisfies<SendSync> for T
where T: Send + Sync,

Source§

impl<T> Satisfies<ThreadLocal> for T