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
TypeIdto prevent duplicate definitions and handle recursion - Type registrations for the
$typesnamespace
Implementations§
Source§impl SchemaBuilder
impl SchemaBuilder
Sourcepub fn new() -> SchemaBuilder
pub fn new() -> SchemaBuilder
Create a new schema builder.
Sourcepub fn build<T>(&mut self) -> SchemaNodeIdwhere
T: BuildSchema + 'static,
pub fn build<T>(&mut self) -> SchemaNodeIdwhere
T: BuildSchema + 'static,
Build the schema for type T, with caching and recursion handling.
This is the primary method for building nested types. It:
- Returns cached ID if already built (idempotent)
- Reserves a node slot before building (handles recursion)
- Calls
T::build_schema()to get the content - For named types: registers in $types and returns a Reference node
Sourcepub fn create_node(&mut self, content: SchemaNodeContent) -> SchemaNodeId
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>().
Sourcepub fn create_node_with_metadata(
&mut self,
content: SchemaNodeContent,
metadata: SchemaMetadata,
) -> SchemaNodeId
pub fn create_node_with_metadata( &mut self, content: SchemaNodeContent, metadata: SchemaMetadata, ) -> SchemaNodeId
Create a schema node with content and metadata.
Sourcepub fn node_mut(&mut self, id: SchemaNodeId) -> &mut SchemaNode
pub fn node_mut(&mut self, id: SchemaNodeId) -> &mut SchemaNode
Get mutable access to a node for adding ext_types or modifying metadata.
Sourcepub fn register_type(&mut self, name: &str, id: SchemaNodeId)
pub fn register_type(&mut self, name: &str, id: SchemaNodeId)
Register a named type in the $types namespace.
Sourcepub fn finish(self, root: SchemaNodeId) -> SchemaDocument
pub fn finish(self, root: SchemaNodeId) -> SchemaDocument
Consume the builder and produce the final schema document.
Trait Implementations§
Source§impl Default for SchemaBuilder
impl Default for SchemaBuilder
Source§fn default() -> SchemaBuilder
fn default() -> SchemaBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SchemaBuilder
impl RefUnwindSafe for SchemaBuilder
impl Send for SchemaBuilder
impl Sync for SchemaBuilder
impl Unpin for SchemaBuilder
impl UnwindSafe for SchemaBuilder
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
Mutably borrows from an owned value. Read more