Trait Inherits
pub unsafe trait Inherits<Base>: Sized {
// Provided methods
fn upcast(self) -> Base { ... }
fn upcast_ref(&self) -> &Base { ... }
}Expand description
Inheritance relationship for Kanzi classes.
The relationship is both transitive and reflexive.
§Usage
The main usage for this trait is to allow safe automatic dereference to a less specific type.
This provides a limited support for subtyping, allowing, for example Node methods to be
called on its parents Node2D and Node3D.
let node_2d: &Node2D = screen.upcast_ref();
let node: Node = node_2d.clone().upcast();
// `Screen` has access to `get_name`, even though it is defined on `Node`.
assert_eq!(screen.get_name()?, node.get_name()?);§Safety
Inherits is an internal trait and shouldn’t be implemented by users directly.
Both (Base and Self) types should use transparent representation and should
contain pointers to corresponding C++ wrappers.
Provided Methods§
fn upcast(self) -> Base
fn upcast_ref(&self) -> &Base
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.