#[repr(C)]pub struct Shape {
pub id: ConstTypeId,
pub layout: ShapeLayout,
pub vtable: ValueVTable,
pub ty: Type,
pub def: Def,
pub type_identifier: &'static str,
pub type_params: &'static [TypeParam],
pub doc: &'static [&'static str],
pub attributes: &'static [ShapeAttribute],
pub type_tag: Option<&'static str>,
pub inner: Option<&'static Shape>,
}Expand description
Schema for reflection of a type
Fields§
§id: ConstTypeIdUnique type identifier, provided by the compiler.
layout: ShapeLayoutSize, alignment — enough to allocate a value of this type (but not initialize it.)
vtable: ValueVTableFunction 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 the shape has ShapeLayout::Unsized, then the parent pointer needs to be passed.
There are more specific vtables in variants of Def
ty: TypeUnderlying type: primitive, sequence, user, pointer.
This follows the Rust Reference, but
omits function types, and trait types, as they cannot be represented here.
def: DefFunctional definition of the value: details for scalars, functions for inserting values into a map, or fetching a value from a list.
type_identifier: &'static strIdentifier for a type: the type’s name without generic parameters. To get the type’s full
name with generic parameters, see ValueVTable::type_name.
type_params: &'static [TypeParam]Generic parameters for the shape
doc: &'static [&'static str]Doc comment lines, collected by facet-macros. Note that they tend to start with a space.
attributes: &'static [ShapeAttribute]Attributes that can be applied to a shape
type_tag: Option<&'static str>Shape type tag, used to identify the type in self describing formats.
For some formats, this is a fully or partially qualified name. For other formats, this is a simple string or integer type.
inner: Option<&'static Shape>As far as serialization and deserialization goes, we consider that this shape is a wrapper
for that shape This is true for “newtypes” like NonZero, wrappers like Utf8PathBuf,
smart pointers like Arc<T>, etc.
When this is set, deserialization takes that into account. For example, facet-json doesn’t expect:
{ “NonZero”: { “value”: 128 } }
It expects just
128
Same for Utf8PathBuf, which is parsed from and serialized to “just a string”.
See Partial’s innermost_shape function (and its support in put).
Implementations§
Source§impl Shape
impl Shape
Sourcepub const fn is(&self, characteristic: Characteristic) -> bool
pub const fn is(&self, characteristic: Characteristic) -> bool
Checks if a shape has the given characteristic.
Sourcepub const fn is_display(&self) -> bool
pub const fn is_display(&self) -> bool
Check if this shape implements the Display trait
Sourcepub const fn is_partial_eq(&self) -> bool
pub const fn is_partial_eq(&self) -> bool
Check if this shape implements the PartialEq trait
Sourcepub const fn is_partial_ord(&self) -> bool
pub const fn is_partial_ord(&self) -> bool
Check if this shape implements the PartialOrd trait
Sourcepub const fn is_default(&self) -> bool
pub const fn is_default(&self) -> bool
Check if this shape implements the Default trait
Sourcepub const fn is_from_str(&self) -> bool
pub const fn is_from_str(&self) -> bool
Check if this shape implements the FromStr trait
Sourcepub fn write_type_name(
&self,
f: &mut Formatter<'_>,
opts: TypeNameOpts,
) -> Result
pub fn write_type_name( &self, f: &mut Formatter<'_>, opts: TypeNameOpts, ) -> Result
Writes the name of this type to the given formatter
Source§impl Shape
impl Shape
Sourcepub const fn builder_for_sized<T>() -> ShapeBuilder
pub const fn builder_for_sized<T>() -> ShapeBuilder
Returns a builder for a shape for some type T.
Sourcepub const fn builder_for_unsized<T: ?Sized>() -> ShapeBuilder
pub const fn builder_for_unsized<T: ?Sized>() -> ShapeBuilder
Returns a builder for a shape for some type T.
Sourcepub fn is_type<'facet, Other: Facet<'facet>>(&self) -> bool
pub fn is_type<'facet, Other: Facet<'facet>>(&self) -> bool
Check if this shape is of the given type
Sourcepub fn assert_type<'facet, Other: Facet<'facet>>(&self)
pub fn assert_type<'facet, Other: Facet<'facet>>(&self)
Assert that this shape is of the given type, panicking if it’s not
Sourcepub fn has_deny_unknown_fields_attr(&self) -> bool
pub fn has_deny_unknown_fields_attr(&self) -> bool
Sourcepub fn has_default_attr(&self) -> bool
pub fn has_default_attr(&self) -> bool
Sourcepub fn get_rename_all_attr(&self) -> Option<&str>
pub fn get_rename_all_attr(&self) -> Option<&str>
Source§impl Shape
impl Shape
Sourcepub fn allocate(&self) -> Result<PtrUninit<'static>, UnsizedError>
pub fn allocate(&self) -> Result<PtrUninit<'static>, UnsizedError>
Heap-allocate a value of this shape
Sourcepub unsafe fn deallocate_mut(&self, ptr: PtrMut<'_>) -> Result<(), UnsizedError>
pub unsafe fn deallocate_mut(&self, ptr: PtrMut<'_>) -> Result<(), UnsizedError>
Deallocate a heap-allocated value of this shape
§Safety
ptrmust have been allocated usingSelf::allocateand be aligned for this shape.ptrmust point to a region that is not already deallocated.
Sourcepub unsafe fn deallocate_uninit(
&self,
ptr: PtrUninit<'static>,
) -> Result<(), UnsizedError>
pub unsafe fn deallocate_uninit( &self, ptr: PtrUninit<'static>, ) -> Result<(), UnsizedError>
Deallocate a heap-allocated, uninitialized value of this shape.
§Safety
ptrmust have been allocated usingSelf::allocate(or equivalent) for this shape.ptrmust not have been already deallocated.ptrmust be properly aligned for this shape.