Trait cpp_utils::StaticCast [] [src]

pub trait StaticCast<T> {
    fn static_cast(&self) -> &T;
    fn static_cast_mut(&mut self) -> &mut T;
}

Provides access to C++ static_cast conversion from derived class to base class.

This trait is automatically implemented by cpp_to_rust. If T1 class is derived (in C++) from T2 class, StaticCast<T2> is implemented for T1.

StaticCast allows to convert a reference to a class into a reference to a base class.

static_cast and static_cast_mut free functions can be used to convert pointer types.

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 cpp_to_rust do not have any information about these implementation details, so all calls of static_cast are wrapper in FFI functions. Still, static_cast is faster than casts with runtime checks on C++ side because runtime overhead of Rust wrapper functions is the same for all cast types.

Required Methods

Convert type of a const reference.

Convert type of a mutable reference.

Implementors