pub struct Schema { /* private fields */ }Expand description
A compiled schema: a finite tree of constraints, plus its content address.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn parse(text: &str) -> Result<Self, SchemaError>
pub fn parse(text: &str) -> Result<Self, SchemaError>
Compile a schema from JSON text.
§Errors
SchemaError if the text is not JSON, or the schema uses a keyword
outside SUPPORTED_KEYWORDS.
Sourcepub fn compile(value: &Value) -> Result<Self, SchemaError>
pub fn compile(value: &Value) -> Result<Self, SchemaError>
Compile an already-parsed schema.
§Errors
SchemaError if the schema uses a keyword outside
SUPPORTED_KEYWORDS, nests deeper than MAX_DEPTH, or gives a
keyword a value of the wrong shape.
Sourcepub const fn digest(&self) -> Digest
pub const fn digest(&self) -> Digest
The schema’s content address.
Recorded in every piece of evidence this schema produces, so a verdict says which schema it was reached against. Two schemas that differ by so much as a whitespace-insensitive key ordering share a digest; two that differ in a constraint do not.
Sourcepub fn validate(&self, value: &Value) -> Validation
pub fn validate(&self, value: &Value) -> Validation
Validate a value, with the default step budget.
Sourcepub fn validate_within(&self, value: &Value, budget: usize) -> Validation
pub fn validate_within(&self, value: &Value, budget: usize) -> Validation
Validate a value, giving up after budget comparisons.
See the module documentation for why exhaustion is its own outcome.