pub unsafe trait Inherits<T: GarbageCollected + 'static>: GarbageCollected + 'static { }Expand description
Indicates that Self is a CppGC type that structurally inherits from T.
When implemented for a type, it declares that Self contains T as its
first field (at offset 0) in a #[repr(C)] layout. This enables the runtime
to safely reinterpret a pointer to the derived type as a pointer to the base
type, allowing base-class methods to operate on derived instances.
This trait is transitive: if C: Inherits<B> and B: Inherits<A>, then
C: Inherits<A> is also implemented automatically by the derive macro.
§Safety
The implementor must guarantee that:
Selfis#[repr(C)].- The first field of
Selfis of typeTand is at offset 0. Tis a valid CppGC type (implementsGarbageCollected).
These invariants ensure that a CppGcObject<Self> pointer can be safely
cast to CppGcObject<T>, because the tag field and the base type’s
fields are at the same memory offsets in both layouts.
Use #[derive(CppgcInherits)] with #[cppgc_inherits_from(BaseType)]
instead of implementing this trait manually. The derive macro validates
the layout requirements at compile time.