pub trait Upcast: Sealed {
type Pointee;
type Cast<B>;
// Required method
fn upcast<B>(self) -> Self::Cast<B>
where Self::Pointee: Inherits<B>;
}Expand description
Converts a raw pointer to a class into a pointer to one of its base
classes, keeping it *mut or *const.
A plain cast, valid because of Inherits. It never dereferences, so null
and dangling pointers stay null or dangling. Implemented only for raw
pointers.
§Examples
A type that isn’t a base doesn’t compile:
ⓘ
use imping_runtime::Upcast;
#[repr(C)]
struct Entity { health: i32 }
#[repr(C)]
struct Item { count: i32 }
let item: *mut Item = core::ptr::null_mut();
let entity: *mut Entity = item.upcast(); // `Item` does not inherit `Entity`Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".