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.
Source§impl Shape
impl Shape
Sourcepub unsafe fn get_scalar_contents<'a>(
&self,
ptr: *const u8,
) -> ScalarContents<'a>
pub unsafe fn get_scalar_contents<'a>( &self, ptr: *const u8, ) -> ScalarContents<'a>
Extract the scalar contents from a shape and a pointer
§Safety
This function is unsafe because it reads from raw memory. The caller must ensure that:
- The pointer points to a valid, initialized value of the correct type
- The memory is properly aligned for the type
- The memory is not mutated while the returned ScalarContents is in use
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.
Sourcepub fn variants(&self) -> &'static [Variant]
pub fn variants(&self) -> &'static [Variant]
Returns a slice of enum variants, if this shape represents an enum
Sourcepub fn variant_by_name(&self, name: &str) -> Option<&Variant>
pub fn variant_by_name(&self, name: &str) -> Option<&Variant>
Returns a reference to a variant with the given name, if it exists
Sourcepub fn variant_by_index(&self, index: usize) -> Result<&Variant, VariantError>
pub fn variant_by_index(&self, index: usize) -> Result<&Variant, VariantError>
Returns a reference to a variant with the given index, if it exists