pub unsafe trait ObjectType:
StaticType
+ Upcast<FerroObject>
+ Sized {
type Parent: ObjectType;
type VTable: Copy + 'static;
// Required methods
fn vtable() -> &'static Self::VTable;
fn register_class();
}Expand description
Implemented by every class.
§Safety
Implemented only by [ferro_class!] (and by hand for the root class).
Implementors guarantee that:
Selfis#[repr(C)]-compatible withParentat offset zero, i.e. a pointer toSelfis a valid pointer to every class in its ancestor chain;VTablelikewise starts withParent::VTableat offset zero;- values of
Selfare only created throughinstantiate(class structs have a privatebasefield andconstruct-style constructors that are only meaningful insideinstantiate).
Required Associated Types§
Sourcetype Parent: ObjectType
type Parent: ObjectType
The base class. The root class is its own parent.
Required Methods§
Sourcefn vtable() -> &'static Self::VTable
fn vtable() -> &'static Self::VTable
The virtual table used by instances whose most-derived class is Self.
Sourcefn register_class()
fn register_class()
The static initialisation of the class. The first call on a thread, after doing the same for the base class:
- makes the type known by name (
TypeInfo::find); - registers the handle type
Ref<Self>and the interface handles the class declares ([ferro_class_info!]) with the untyped value conversions; - registers the properties of the class in declaration order
(
ferro_properties!); - runs the static constructor of the class
(
ClassDefaults::static_constructor).
Later calls only read a thread-local flag.
Generated by ferro_class!. Called by instantiate, so a class
that has an instance on the thread is initialised, and through
TypeInfo::ensure_class_init by property accessors and the property
registry, for classes that have none.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".