[][src]Trait cpp_core::StaticUpcast

pub trait StaticUpcast<T>: Sized {
    unsafe fn static_upcast(ptr: Ptr<Self>) -> Ptr<T>;
unsafe fn static_upcast_mut(ptr: MutPtr<Self>) -> MutPtr<T>; }

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 and static_upcast_mut methods on pointer types (CppBox, Ptr, MutPtr, Ref, MutRef) 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

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.

unsafe fn static_upcast_mut(ptr: MutPtr<Self>) -> MutPtr<T>

Convert type of a mutable pointer.

Safety

This operation is safe as long as ptr is either valid or null.

Loading content...

Implementors

impl<T> StaticUpcast<T> for T[src]

Loading content...