Skip to main content

Builder

Struct Builder 

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

Hash-consing arena builder. Structurally equal subtrees collapse to one NodeId because every side blob is content-interned, so equal children yield equal Node values.

Implementations§

Source§

impl Builder

Source

pub fn new(options: CompileOptions) -> Self

A new builder with the given options.

Source

pub fn null(&mut self) -> Result<NodeId, CompileError>

Interns a null node.

Source

pub fn boolean(&mut self) -> Result<NodeId, CompileError>

Interns a boolean node.

Source

pub fn never(&mut self) -> Result<NodeId, CompileError>

Interns a node matching no value at all (the bare false schema).

Source

pub fn string_const(&mut self, value: &str) -> Result<NodeId, CompileError>

Interns a string-const node.

Source

pub fn string_pattern( &mut self, regex: &str, min_len: Option<u32>, max_len: Option<u32>, charset: Charset, ) -> Result<NodeId, CompileError>

Interns a string-pattern node.

Source

pub fn integer( &mut self, minimum: Option<i64>, maximum: Option<i64>, ) -> Result<NodeId, CompileError>

Interns an integer node.

Source

pub fn integer_multiple_of( &mut self, minimum: Option<i64>, maximum: Option<i64>, multiple_of: Option<u64>, ) -> Result<NodeId, CompileError>

Interns an integer node with an exact multipleOf divisor.

Source

pub fn number(&mut self) -> Result<NodeId, CompileError>

Interns an unbounded number node (the full JSON numeric grammar).

Source

pub fn number_range( &mut self, minimum: Option<(i128, u32, bool)>, maximum: Option<(i128, u32, bool)>, multiple_of: Option<(u64, u32)>, ) -> Result<NodeId, CompileError>

Interns a number node with an integer-valued inclusive/exclusive bound and/or a decimal multipleOf (coef * 10^-exp).

Source

pub fn integer_number_range( &mut self, minimum: Option<(i128, u32, bool)>, maximum: Option<(i128, u32, bool)>, multiple_of: Option<(u64, u32)>, ) -> Result<NodeId, CompileError>

Interns exact decimal constraints whose accepted values must be mathematically integral.

Source

pub fn lexical_number(&mut self, regex: &str) -> Result<NodeId, CompileError>

Interns a lexical JSON-number constraint.

Source

pub fn enum_values( &mut self, values: Vec<ScalarLit>, ) -> Result<NodeId, CompileError>

Interns an enum node. Values are canonically sorted; a duplicate value is rejected.

Source

pub fn array( &mut self, items: NodeId, min_items: u32, max_items: Option<u32>, ) -> Result<NodeId, CompileError>

Interns an array node.

Source

pub fn array_unique( &mut self, items: NodeId, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>

Interns an array node with an explicit uniqueItems flag.

Source

pub fn array_open( &mut self, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>

Interns an array node with unconstrained (items: true or absent) elements.

Source

pub fn array_full( &mut self, items: ItemsPolicy, min_items: u32, max_items: Option<u32>, unique_items: bool, contains: Option<ContainsConstraint>, items_annotates: bool, ) -> Result<NodeId, CompileError>

Interns an array node with every keyword explicit, including contains and whether items was textually present (items_annotates, for unevaluatedItems).

Source

pub fn tuple( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, ) -> Result<NodeId, CompileError>

Interns a tuple array with positional prefix schemas and an optional tail schema. Closed tuples whose minimum exceeds the prefix length are rejected.

Source

pub fn tuple_unique( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>

Interns a positional (tuple) array node with an explicit uniqueItems flag.

Source

pub fn tuple_full( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, unique_items: bool, contains: Option<ContainsConstraint>, tail_annotates: bool, ) -> Result<NodeId, CompileError>

Interns a positional (tuple) array node with every keyword explicit, including contains and whether the tail was textually present (tail_annotates, for unevaluatedItems).

Source

pub fn union_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>

Interns a type-union node. branches are child nodes in declaration order; a single branch collapses to that branch directly rather than a one-element union.

Source

pub fn alloc_def_slot(&mut self) -> Result<u32, CompileError>

Reserves a def slot for a recursive definition and returns its index. The slot is filled by Builder::set_def_target once the body is lowered; a Node::Ref may point at it meanwhile.

Source

pub fn set_def_target( &mut self, slot: u32, body: NodeId, ) -> Result<(), CompileError>

Points a reserved def slot at its lowered body root. Fails on an out-of-range slot or one already assigned, rather than silently overwriting or indexing out of bounds.

Source

pub fn ref_node(&mut self, def: u32) -> Result<NodeId, CompileError>

Interns a Node::Ref naming a reserved def slot (a recursion cut point).

Source

pub fn dynamic_ref( &mut self, initial_target: NodeId, anchor: AnchorId, ) -> Result<NodeId, CompileError>

Interns an already-statically-resolved dynamic reference.

Source

pub fn unevaluated( &mut self, kind: UnevaluatedKind, scope: NodeId, unevaluated: NodeId, ) -> Result<NodeId, CompileError>

Interns an unevaluatedProperties/unevaluatedItems obligation over scope, with unevaluated applied to each member scope did not annotate.

Source

pub fn intersection_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>

Interns an allOf intersection in declaration order. A single branch collapses to itself.

Source

pub fn exactly_one_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>

Interns a oneOf exactly-one node in declaration order. A single branch collapses to itself because exactly-one preserves its language.

Source

pub fn not(&mut self, inner: NodeId) -> Result<NodeId, CompileError>

Interns a not: matches any complete JSON value inner does not.

Source

pub fn object( &mut self, fields: Vec<(String, NodeId)>, required: &[bool], closure: ObjectClosure, ) -> Result<NodeId, CompileError>

Interns an object node. fields are (name, child) in source order; required is aligned to fields by position. A duplicate field name is rejected.

Source

pub fn object_full( &mut self, fields: Vec<(String, NodeId)>, required: &[bool], closure: ObjectClosure, dependent: Vec<(String, NodeId)>, dependent_required: Vec<(String, Vec<String>)>, ) -> Result<NodeId, CompileError>

Interns an object with dependentSchemas: (key, schema) pairs where key’s presence in the instance additionally requires the whole instance to satisfy schema.

Source

pub fn open_object( &mut self, known: Vec<(String, NodeId)>, known_required: &[bool], patterns: Vec<(String, NodeId)>, additional: AdditionalPolicy, property_names: Option<NodeId>, min_properties: Option<u32>, max_properties: Option<u32>, ) -> Result<NodeId, CompileError>

Interns an order-independent open object. known/known_required behave like object’s fields/required; patterns are (regex, child) patternProperties entries.

Source

pub fn open_object_full( &mut self, known: Vec<(String, NodeId)>, known_required: &[bool], patterns: Vec<(String, NodeId)>, additional: AdditionalPolicy, property_names: Option<NodeId>, min_properties: Option<u32>, max_properties: Option<u32>, dependent: Vec<(String, NodeId)>, dependent_required: Vec<(String, Vec<String>)>, ) -> Result<NodeId, CompileError>

Interns an order-independent open object with dependentSchemas, same semantics as object_full’s.

Source

pub fn unsupported( &mut self, keyword: &str, reason: UnsupportedReason, json_pointer: &str, ) -> Result<NodeId, CompileError>

Interns an Unsupported node and records a diagnostic for this occurrence. Returns the node id, or TooManyDiagnostics once the bounded buffer is full.

Source

pub fn finish(self, root: NodeId) -> Result<SchemaIR, CompileError>

Freezes the arena into an immutable IR rooted at root, running full validation.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.