pub struct Shape {
pub name: NameFn,
pub typeid: TypeId,
pub layout: Layout,
pub innards: Innards,
pub set_to_default: Option<SetToDefaultFn>,
pub drop_in_place: Option<DropFn>,
}
Expand description
Schema for reflection of a type
Fields§
§name: NameFn
A descriptive name for the type, e.g. u64
, or Person
typeid: TypeId
The typeid of the underlying type
layout: Layout
Size & alignment
innards: Innards
Details/contents of the value
set_to_default: Option<SetToDefaultFn>
Set the value at a given address to the default value for this type
drop_in_place: Option<DropFn>
Drop the value at a given address
§Safety
This function should be called only for initialized values. It’s the caller’s responsibility to ensure the address points to a valid value.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn pretty_print_recursive(&self, f: &mut Formatter<'_>) -> Result
pub fn pretty_print_recursive(&self, f: &mut Formatter<'_>) -> Result
Pretty-print this shape, recursively.
Sourcepub fn known_fields(&self) -> &'static [Field]
pub fn known_fields(&self) -> &'static [Field]
Returns a slice of statically known fields. Fields that are not in there might still be inserted if it’s a dynamic collection.
Sourcepub fn field_by_name(&self, name: &str) -> Option<&Field>
pub fn field_by_name(&self, name: &str) -> Option<&Field>
Returns a reference to a field with the given name, if it exists
Sourcepub fn field_by_index(&self, index: usize) -> Result<&Field, FieldError>
pub fn field_by_index(&self, index: usize) -> Result<&Field, FieldError>
Returns a reference to a field with the given index, if it exists
Sourcepub fn dangling(&self) -> NonNull<u8>
pub fn dangling(&self) -> NonNull<u8>
Returns a dangling pointer for this shape.
This is useful for zero-sized types (ZSTs) which don’t need actual memory allocation, but still need a properly aligned “some address”.
§Safety
This function returns a dangling pointer. It should only be used in contexts where a non-null pointer is required but no actual memory access will occur, such as for ZSTs.