Skip to main content

SchemaBuilder

Struct SchemaBuilder 

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

Builder for constructing schema documents from Rust types.

The builder maintains:

  • An arena of schema nodes
  • A cache by TypeId to prevent duplicate definitions and handle recursion
  • Type registrations for the $types namespace

Implementations§

Source§

impl SchemaBuilder

Source

pub fn new() -> Self

Create a new schema builder.

Source

pub fn build<T: BuildSchema + 'static>(&mut self) -> SchemaNodeId

Build the schema for type T, with caching and recursion handling.

This is the primary method for building nested types. It:

  1. Returns cached ID if already built (idempotent)
  2. Reserves a node slot before building (handles recursion)
  3. Calls T::build_schema() to get the content
  4. For named types: registers in $types and returns a Reference node
Source

pub fn create_node(&mut self, content: SchemaNodeContent) -> SchemaNodeId

Create a schema node with the given content.

Use this for creating anonymous/inline nodes that don’t need caching. For types that implement BuildSchema, prefer build::<T>().

Source

pub fn create_node_with_metadata( &mut self, content: SchemaNodeContent, metadata: SchemaMetadata, ) -> SchemaNodeId

Create a schema node with content and metadata.

Source

pub fn node_mut(&mut self, id: SchemaNodeId) -> &mut SchemaNode

Get mutable access to a node for adding ext_types or modifying metadata.

Source

pub fn register_type(&mut self, name: &str, id: SchemaNodeId)

Register a named type in the $types namespace.

Source

pub fn finish(self, root: SchemaNodeId) -> SchemaDocument

Consume the builder and produce the final schema document.

Trait Implementations§

Source§

impl Default for SchemaBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.