pub struct SchemaState {
pub is_complete: bool,
/* private fields */
}Expand description
State machine that tracks JSON generation progress against a schema.
Characters are fed one at a time; the machine maintains a stack of context frames mirroring the nesting structure of the JSON being generated.
Fields§
§is_complete: boolWhether we’ve completed the root value.
Implementations§
Source§impl SchemaState
impl SchemaState
Sourcepub fn new(schema: &SchemaType) -> Self
pub fn new(schema: &SchemaType) -> Self
Create a new state machine rooted at the given schema.
Sourcepub fn feed_char(&mut self, ch: char) -> Result<bool, SchemaError>
pub fn feed_char(&mut self, ch: char) -> Result<bool, SchemaError>
Feed a character and check if it’s valid according to the schema.
Returns Ok(true) if the character was accepted, Ok(false) if it
was rejected but didn’t violate hard constraints, or Err on a
definite schema violation.
Sourcepub fn valid_next_chars(&self) -> Vec<char>
pub fn valid_next_chars(&self) -> Vec<char>
Get the set of valid next characters at the current position.
This is a simplified heuristic — for complex schemas, the set may be conservative (allowing more than strictly valid).
Sourcepub fn continuation_pattern(&self) -> String
pub fn continuation_pattern(&self) -> String
Get a regex pattern for valid continuations (for masking logits).
Trait Implementations§
Source§impl Clone for SchemaState
impl Clone for SchemaState
Source§fn clone(&self) -> SchemaState
fn clone(&self) -> SchemaState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SchemaState
impl RefUnwindSafe for SchemaState
impl Send for SchemaState
impl Sync for SchemaState
impl Unpin for SchemaState
impl UnsafeUnpin for SchemaState
impl UnwindSafe for SchemaState
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more