pub struct Casts { /* private fields */ }
Expand description
Stores known ways to cast from concrete types to trait objects.
Implementations
sourceimpl Casts
impl Casts
sourcepub unsafe fn add<T, U>(&mut self, cast: fn(_: *const T) -> *const U) where
T: 'static,
U: ?Sized + 'static,
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.
sourcepub fn find_key(&self, src_type: TypeId, dst_type: TypeId) -> Option<u32>
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
.
sourcepub fn cast<Dst>(&self, key: u32, src: *const ()) -> *const Dst where
Dst: ?Sized + 'static,
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.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more