pub unsafe trait Facet<'facet>: 'facet {
const SHAPE: &'static Shape;
const VTABLE: &'static ValueVTable;
}
Expand description
Allows querying the Shape
of a type, which in turn lets us inspect any fields, build a value of
this type progressively, etc.
The 'facet
lifetime allows Facet
to be derived for types that borrow from something else.
§Safety
If you implement this wrong, all the safe abstractions in facet-reflect
,
all the serializers, deserializers, the entire ecosystem is unsafe.
You’re responsible for describing the type layout properly, and annotating all the invariants.
Required Associated Constants§
Sourceconst SHAPE: &'static Shape
const SHAPE: &'static Shape
The shape of this type
Shape embeds all other constants of this trait.
Sourceconst VTABLE: &'static ValueVTable
const VTABLE: &'static ValueVTable
Function pointers to perform various operations: print the full type name (with generic type parameters), use the Display implementation, the Debug implementation, build a default value, clone, etc.
If Self::SHAPE
has ShapeLayout::Unsized
, then the parent pointer needs to be passed.
There are more specific vtables in variants of Def
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.