pub struct CompiledSchema { /* private fields */ }Expand description
A JSON Schema compiled once and reused.
Cheap to clone: the validator sits behind an Arc.
Implementations§
Source§impl CompiledSchema
impl CompiledSchema
Sourcepub fn compile(schema: &Value) -> Result<Self, SchemaCompileError>
pub fn compile(schema: &Value) -> Result<Self, SchemaCompileError>
Compiles schema.
§Errors
Returns SchemaCompileError when the value is not a valid schema.
use serde_json::json;
use turnframe_provider::structured::CompiledSchema;
let schema = CompiledSchema::compile(&json!({
"type": "object",
"properties": {"n": {"type": "integer"}},
"required": ["n"],
"additionalProperties": false
}))?;
assert!(schema.validate(&json!({"n": 1})).is_ok());
assert!(schema.validate(&json!({"n": "one"})).is_err());Sourcepub fn fingerprint(&self) -> &Digest
pub fn fingerprint(&self) -> &Digest
Canonical digest of the schema; the SchemaCache key, and a stable
label to record in a replay entry.
Sourcepub fn validate(&self, instance: &Value) -> Result<(), StructuredOutputError>
pub fn validate(&self, instance: &Value) -> Result<(), StructuredOutputError>
Validates instance, reporting the single most actionable failure.
When a document breaks the schema in several ways at once, the reported one is chosen by a fixed priority — unknown field, then missing field, then any other violation — so the same document always yields the same error, whatever order the validator walks in.
§Errors
Returns the classified StructuredOutputError.
Trait Implementations§
Source§impl Clone for CompiledSchema
impl Clone for CompiledSchema
Source§impl Debug for CompiledSchema
impl Debug for CompiledSchema
impl Eq for CompiledSchema
Auto Trait Implementations§
impl !RefUnwindSafe for CompiledSchema
impl !UnwindSafe for CompiledSchema
impl Freeze for CompiledSchema
impl Send for CompiledSchema
impl Sync for CompiledSchema
impl Unpin for CompiledSchema
impl UnsafeUnpin for CompiledSchema
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.