Schema

Struct Schema 

Source
pub struct Schema { /* private fields */ }
Expand description

Cached schema for a type that may contain flattened fields.

This is computed once per Shape and can be cached forever since type information is static.

Implementations§

Source§

impl Schema

Source

pub fn build(shape: &'static Shape) -> Result<Self, SchemaError>

Build a schema for the given shape with flattened enum representation.

Returns an error if the type definition contains conflicts, such as duplicate field names from parent and flattened structs.

Note: This defaults to Flattened representation. For auto-detection based on #[facet(tag = "...")] attributes, use Schema::build_auto.

Source

pub fn build_auto(shape: &'static Shape) -> Result<Self, SchemaError>

Build a schema with auto-detected enum representation based on each enum’s attributes.

This inspects each flattened enum’s shape attributes to determine its representation:

  • #[facet(untagged)] → Flattened
  • #[facet(tag = "type")] → InternallyTagged
  • #[facet(tag = "t", content = "c")] → AdjacentlyTagged
  • No attributes → Flattened (for flatten solver behavior)

For externally-tagged enums (variant name as key), use Schema::build_externally_tagged.

Source

pub fn build_externally_tagged( shape: &'static Shape, ) -> Result<Self, SchemaError>

Build a schema for externally-tagged enum representation (e.g., JSON).

In this representation, the variant name appears as a key and the variant’s content is nested under it. The solver will only expect to see the variant name as a top-level key, not the variant’s fields.

Source

pub fn build_with_repr( shape: &'static Shape, repr: EnumRepr, ) -> Result<Self, SchemaError>

Build a schema with the specified enum representation.

Source

pub fn resolutions(&self) -> &[Resolution]

Get the resolutions for this schema.

Trait Implementations§

Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.