#[non_exhaustive]#[repr(C)]pub struct Shape {
pub id: ConstTypeId,
pub layout: ShapeLayout,
pub vtable: &'static ValueVTable,
pub def: Def,
pub type_params: &'static [TypeParam],
pub doc: &'static [&'static str],
pub attributes: &'static [ShapeAttribute],
pub inner: Option<fn() -> &'static 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: &'static 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.
There are more specific vtables in variants of Def
def: DefFurther definition of the value: details for structs, enums, scalars, options, smart pointers, arrays, slices, tuples, etc.
This typically lists fields (with shapes and offsets), reprs, variants and contains vtables that let you perform other operations, like inserting into a map or fetching a value from a list.
type_params: &'static [TypeParam]Generic parameters for the shape
doc: &'static [&'static str]Doc comment lines, collected by facet-derive. Note that they tend to start with a space.
attributes: &'static [ShapeAttribute]Attributes that can be applied to a shape
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<u8>, 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
impl Shape
Sourcepub const fn is(&'static self, characteristic: Characteristic) -> bool
pub const fn is(&'static self, characteristic: Characteristic) -> bool
Checks if a shape has the given characteristic.
Sourcepub const fn is_display(&'static self) -> bool
pub const fn is_display(&'static self) -> bool
Check if this shape implements the Display trait
Sourcepub const fn is_partial_eq(&'static self) -> bool
pub const fn is_partial_eq(&'static self) -> bool
Check if this shape implements the PartialEq trait
Sourcepub const fn is_partial_ord(&'static self) -> bool
pub const fn is_partial_ord(&'static self) -> bool
Check if this shape implements the PartialOrd trait
Sourcepub const fn is_default(&'static self) -> bool
pub const fn is_default(&'static self) -> bool
Check if this shape implements the Default trait
Sourcepub const fn is_from_str(&'static self) -> bool
pub const fn is_from_str(&'static 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
impl Shape
Sourcepub const fn builder() -> ShapeBuilder
pub const fn builder() -> ShapeBuilder
Returns a builder for 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 fn is_type<Other>(&'static self) -> boolwhere
Other: Facet<'static>,
pub fn is_type<Other>(&'static self) -> boolwhere
Other: Facet<'static>,
Check if this shape is of the given type
Sourcepub fn assert_type<Other>(&'static self)where
Other: Facet<'static>,
pub fn assert_type<Other>(&'static self)where
Other: Facet<'static>,
Assert that this shape is of the given type, panicking if it’s not
Sourcepub fn has_deny_unknown_fields_attr(&'static self) -> bool
pub fn has_deny_unknown_fields_attr(&'static self) -> bool
Sourcepub fn has_default_attr(&'static self) -> bool
pub fn has_default_attr(&'static self) -> bool
Sourcepub fn get_rename_all_attr(&'static self) -> Option<&'static str>
pub fn get_rename_all_attr(&'static self) -> Option<&'static 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 Copy for Shape
impl Eq for Shape
Auto Trait Implementations§
impl Freeze for Shape
impl RefUnwindSafe for Shape
impl Send for Shape
impl Sync for Shape
impl Unpin for Shape
impl UnwindSafe for 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