#[repr(C)]pub struct Shape {
pub id: ConstTypeId,
pub layout: ShapeLayout,
pub vtable: &'static 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<fn() -> &'static Shape>,
}
Expand description
Schema for reflection of a type
Fields§
§id: ConstTypeId
Unique type identifier, provided by the compiler.
layout: ShapeLayout
Size, alignment — enough to allocate a value of this type (but not initialize it.)
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 the shape has ShapeLayout::Unsized
, then the parent pointer needs to be passed.
There are more specific vtables in variants of Def
ty: Type
Underlying type: primitive, sequence, user, pointer.
This follows the Rust Reference
, but
omits function types, and trait types, as they cannot be represented here.
def: Def
Functional definition of the value: details for scalars, functions for inserting values into a map, or fetching a value from a list.
type_identifier: &'static str
Identifier 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<fn() -> &'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 fn is(&self, characteristic: Characteristic) -> bool
pub fn is(&self, characteristic: Characteristic) -> bool
Checks if a shape has the given characteristic.
Sourcepub fn is_display(&self) -> bool
pub fn is_display(&self) -> bool
Check if this shape implements the Display trait
Sourcepub fn is_partial_eq(&self) -> bool
pub fn is_partial_eq(&self) -> bool
Check if this shape implements the PartialEq trait
Sourcepub fn is_partial_ord(&self) -> bool
pub fn is_partial_ord(&self) -> bool
Check if this shape implements the PartialOrd trait
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Check if this shape implements the Default trait
Sourcepub fn is_from_str(&self) -> bool
pub 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<'a, T: Facet<'a>>() -> ShapeBuilder
pub const fn builder_for_sized<'a, T: Facet<'a>>() -> ShapeBuilder
Returns a builder for a shape for some type T
.
Sourcepub const fn builder_for_unsized<'a, T: Facet<'a> + ?Sized>() -> ShapeBuilder
pub const fn builder_for_unsized<'a, T: Facet<'a> + ?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
ptr
must have been allocated usingSelf::allocate
and be aligned for this shape.ptr
must 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
ptr
must have been allocated usingSelf::allocate
(or equivalent) for this shape.ptr
must not have been already deallocated.ptr
must be properly aligned for this shape.