#[non_exhaustive]#[repr(C)]pub struct Shape<'shape> {
pub id: ConstTypeId,
pub layout: ShapeLayout,
pub vtable: &'shape ValueVTable,
pub ty: Type<'shape>,
pub def: Def<'shape>,
pub type_identifier: &'shape str,
pub type_params: &'shape [TypeParam<'shape>],
pub doc: &'shape [&'shape str],
pub attributes: &'shape [ShapeAttribute<'shape>],
pub type_tag: Option<&'shape str>,
pub inner: Option<fn() -> &'shape Shape<'shape>>,
}Expand description
Schema for reflection of a type
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: ConstTypeIdUnique type identifier, provided by the compiler.
layout: ShapeLayoutSize, alignment — enough to allocate a value of this type (but not initialize it.)
vtable: &'shape 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: Type<'shape>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<'shape>Functional definition of the value: details for scalars, functions for inserting values into a map, or fetching a value from a list.
type_identifier: &'shape 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: &'shape [TypeParam<'shape>]Generic parameters for the shape
doc: &'shape [&'shape str]Doc comment lines, collected by facet-derive. Note that they tend to start with a space.
attributes: &'shape [ShapeAttribute<'shape>]Attributes that can be applied to a shape
type_tag: Option<&'shape 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() -> &'shape Shape<'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 Wip’s innermost_shape function (and its support in put).
Implementations§
Source§impl<'shape> Shape<'shape>
impl<'shape> Shape<'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<(), Error>
pub fn write_type_name( &self, f: &mut Formatter<'_>, opts: TypeNameOpts, ) -> Result<(), Error>
Writes the name of this type to the given formatter
Source§impl<'shape> Shape<'shape>
impl<'shape> Shape<'shape>
Sourcepub const fn builder_for_sized<'a, T>() -> ShapeBuilder<'shape>where
T: Facet<'a>,
pub const fn builder_for_sized<'a, T>() -> ShapeBuilder<'shape>where
T: Facet<'a>,
Returns a builder for a shape for some type T.
Sourcepub const fn builder_for_unsized<'a, T>() -> ShapeBuilder<'shape>
pub const fn builder_for_unsized<'a, T>() -> ShapeBuilder<'shape>
Returns a builder for a shape for some type T.
Sourcepub fn is_type<Other>(&self) -> boolwhere
Other: Facet<'shape>,
pub fn is_type<Other>(&self) -> boolwhere
Other: Facet<'shape>,
Check if this shape is of the given type
Sourcepub fn assert_type<Other>(&self)where
Other: Facet<'shape>,
pub fn assert_type<Other>(&self)where
Other: Facet<'shape>,
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.
Trait Implementations§
impl<'shape> Copy for Shape<'shape>
impl Eq for Shape<'_>
Auto Trait Implementations§
impl<'shape> Freeze for Shape<'shape>
impl<'shape> RefUnwindSafe for Shape<'shape>
impl<'shape> Send for Shape<'shape>
impl<'shape> Sync for Shape<'shape>
impl<'shape> Unpin for Shape<'shape>
impl<'shape> UnwindSafe for Shape<'shape>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more