pub unsafe trait Base: GarbageCollected + 'static {
// Provided method
fn inheriting_types() -> &'static [TypeId] { ... }
}Expand description
Marks a CppGC type as a base class that other types may inherit from.
Types implementing Base can be used with [try_unwrap_cppgc_base_object],
which accepts both the base type itself and any type that implements
Inherits<Self>. This is what powers polymorphic method dispatch
on CppGC objects: methods defined on a base class can be called on instances
of any derived class.
The trait provides inheriting_types, which returns
the TypeIds of all types that transitively inherit from Self. This list
is computed once (lazily) using the inheritance graph built by the
CppgcInherits derive macro and cached for the lifetime of the program.
§Safety
The implementor must guarantee that:
Selfis#[repr(C)]and non-zero-sized.- Any type
Dfor whichD: Inherits<Self>holds hasSelfembedded at offset 0, so that aCppGcObject<D>can be safely reinterpreted asCppGcObject<Self>.
Use #[derive(CppgcBase)] instead of implementing this trait manually.
Provided Methods§
Sourcefn inheriting_types() -> &'static [TypeId]
fn inheriting_types() -> &'static [TypeId]
Returns the TypeIds of all types that transitively inherit from this type.
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.