pub trait DynamicCast<T>: Sized {
// Required method
unsafe fn dynamic_cast(ptr: Ptr<Self>) -> Ptr<T>;
}
Expand description
Converts a class pointer to a base class pointer.
A null pointer is always converted to a null pointer. If the object can’t be converted to the requested type, a null pointer is returned.
It’s recommended to perform the conversion by calling dynamic_cast
method on pointer types (CppBox
, Ptr
, Ref
)
instead of importing the trait directly.
Provides access to C++ dynamic_cast
conversion from base class to derived class.
The conversion in opposite direction can be done with StaticUpcast
.
If T1
class is derived (in C++) from T2
class (directly or indirectly),
DynamicCast<T1>
is implemented for T2
.
The implementation is generated by ritual
automatically.
Required Methods§
Sourceunsafe fn dynamic_cast(ptr: Ptr<Self>) -> Ptr<T>
unsafe fn dynamic_cast(ptr: Ptr<Self>) -> Ptr<T>
Convert type of a const pointer.
Returns a null pointer if the object doesn’t have the requested type.
§Safety
This operation is safe as long as ptr
is either valid or null.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.