pub struct Validator { /* private fields */ }Expand description
A compiled schema. Cheap to clone and safe to share between threads.
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn is_valid(&self, instance: &Value) -> bool
pub fn is_valid(&self, instance: &Value) -> bool
Whether the instance is valid. It has no way to report an error, so it fails closed: it reports false both
for a schema that recursed in place beyond the maximum depth and for a match of a regular expression that
reached its limit (see CompileOptions::pattern_match_limit). A limit is never reported as valid. In
neither case is the instance known to be not valid. Use Validator::try_validate to tell them from an
instance that is not valid.
Sourcepub fn try_validate(
&self,
instance: &Value,
) -> Result<bool, SchemaEvaluationError>
pub fn try_validate( &self, instance: &Value, ) -> Result<bool, SchemaEvaluationError>
Whether the instance is valid, or why the evaluation gave no answer: it recursed in place beyond the maximum depth, or a match of a regular expression reached its limit.
Sourcepub fn try_validate_instance<'a, I: Instance<'a>>(
&self,
instance: I,
) -> Result<bool, SchemaEvaluationError>
pub fn try_validate_instance<'a, I: Instance<'a>>( &self, instance: I, ) -> Result<bool, SchemaEvaluationError>
Validator::try_validate for any Instance: a value read in place, such as a host language’s own
objects, with no conversion to serde_json::Value.
Sourcepub fn try_validate_json(
&self,
json: &str,
) -> Result<bool, SchemaEvaluationError>
pub fn try_validate_json( &self, json: &str, ) -> Result<bool, SchemaEvaluationError>
Whether the JSON text is valid, or why there is no answer. The text is parsed into the thread’s reused
buffers and evaluated in place: in the steady state nothing is allocated. Use JsonDocument to validate
the same text more than once.
Sourcepub fn try_evaluate(
&self,
instance: &Value,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, SchemaEvaluationError>
pub fn try_evaluate( &self, instance: &Value, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationError>
Evaluates the instance exhaustively, reporting to the collector. Returns whether it is valid, or why the evaluation gave no answer. With an error the collector’s results are not complete.
Sourcepub fn try_evaluate_instance<'a, I: Instance<'a>>(
&self,
instance: I,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, SchemaEvaluationError>
pub fn try_evaluate_instance<'a, I: Instance<'a>>( &self, instance: I, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationError>
Validator::try_evaluate for any Instance.
Sourcepub fn try_evaluate_json(
&self,
json: &str,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, SchemaEvaluationError>
pub fn try_evaluate_json( &self, json: &str, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationError>
Validator::try_evaluate for JSON text, parsed as Validator::try_validate_json parses it.
Sourcepub fn validate(
&self,
instance: &Value,
) -> Result<bool, SchemaEvaluationDepthError>
pub fn validate( &self, instance: &Value, ) -> Result<bool, SchemaEvaluationDepthError>
Whether the instance is valid, or an error if the validation was abandoned at a limit. The error type has
one value, whose message names both limits, so it does not say whether the evaluation recursed in place
beyond the maximum depth or a match of a regular expression reached its limit: Validator::try_validate
does.
Sourcepub fn evaluate(
&self,
instance: &Value,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, SchemaEvaluationDepthError>
pub fn evaluate( &self, instance: &Value, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationDepthError>
Evaluates the instance exhaustively, reporting to the collector. Returns whether it is valid. The error is
that of Validator::validate, for a validation abandoned at either limit: Validator::try_evaluate
says which.
Sourcepub fn validate_instance<'a, I: Instance<'a>>(
&self,
instance: I,
) -> Result<bool, SchemaEvaluationDepthError>
pub fn validate_instance<'a, I: Instance<'a>>( &self, instance: I, ) -> Result<bool, SchemaEvaluationDepthError>
Validator::validate for any Instance: a value read in place, such as a host language’s own objects,
with no conversion to serde_json::Value. The error is that of Validator::validate, for a validation
abandoned at either limit: Validator::try_validate_instance says which.
Sourcepub fn validate_json(&self, json: &str) -> Result<bool, JsonValidationError>
pub fn validate_json(&self, json: &str) -> Result<bool, JsonValidationError>
Whether the JSON text is valid. The text is parsed into the thread’s reused buffers and evaluated in place: in
the steady state nothing is allocated. Use JsonDocument to validate the same text more than once. An
evaluation that was abandoned is reported as JsonValidationError::DepthExceeded, whichever limit it
reached: Validator::try_validate_json says which.
Sourcepub fn evaluate_json(
&self,
json: &str,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, JsonValidationError>
pub fn evaluate_json( &self, json: &str, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, JsonValidationError>
Validator::evaluate for JSON text, parsed as Validator::validate_json parses it. An evaluation that
was abandoned is JsonValidationError::DepthExceeded, whichever limit it reached:
Validator::try_evaluate_json says which.
Sourcepub fn evaluate_instance<'a, I: Instance<'a>>(
&self,
instance: I,
collector: &mut JsonSchemaResultsCollector,
) -> Result<bool, SchemaEvaluationDepthError>
pub fn evaluate_instance<'a, I: Instance<'a>>( &self, instance: I, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationDepthError>
Validator::evaluate for any Instance. The error is that of Validator::validate, for a validation
abandoned at either limit: Validator::try_evaluate_instance says which.