Trait StaticUpcast

Source
pub trait StaticUpcast<T>: Sized {
    // Required method
    unsafe fn static_upcast(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. Otherwise, the provided pointer must be valid.

It’s recommended to perform the conversion by calling static_upcast method on pointer types (CppBox, Ptr, Ref) instead of importing the trait directly.

Provides access to C++ static_cast conversion from derived class to base class. The conversion in opposite direction can be done with StaticDowncast.

If T1 class is derived (in C++) from T2 class (directly or indirectly), StaticUpcast<T2> is implemented for T1. The implementation is generated by ritual automatically.

Note that Rust functions associated with this trait have runtime overhead. In C++, static_cast is usually a no-op if there is no multiple inheritance, and multiple inheritance requires pointer adjustment. However, Rust compiler and ritual do not have any information about these implementation details, so all calls of static_cast are wrapper in FFI functions.

Required Methods§

Source

unsafe fn static_upcast(ptr: Ptr<Self>) -> Ptr<T>

Convert type of a const pointer.

§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.

Implementors§

Source§

impl<T> StaticUpcast<T> for T