Skip to main content

Validator

Struct Validator 

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

A compiled schema. Cheap to clone and safe to share between threads.

Implementations§

Source§

impl Validator

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn try_evaluate_instance<'a, I: Instance<'a>>( &self, instance: I, collector: &mut JsonSchemaResultsCollector, ) -> Result<bool, SchemaEvaluationError>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Validator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Validator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.