pub unsafe trait CastFrom<T> {
// Required method
fn cast(t: *mut T) -> *mut Self;
}
Expand description
Helper trait for the MetaTable
.
This trait is required to be implemented for a trait to be compatible with the meta table.
§Safety
The produced pointer must have the same provenance and address as the
provided pointer and a vtable that is valid for the type T
.
§Examples
use shred::CastFrom;
trait Foo {
fn foo1(&self);
fn foo2(&mut self, x: i32) -> i32;
}
unsafe impl<T> CastFrom<T> for dyn Foo
where
T: Foo + 'static,
{
fn cast(t: *mut T) -> *mut (dyn Foo + 'static) {
t
}
}
Required Methods§
Object Safety§
This trait is not object safe.