Struct Config

Source
pub struct Config<'a> { /* private fields */ }
Expand description

A structure to hold configuration for a validation run.

Implementations§

Source§

impl<'a> Config<'a>

Source

pub fn get_validator<'v>( &self, key: &'v str, ) -> Option<fn(cfg: &'v Config<'v>, instance: &'v Value, schema: &'v Value, parent_schema: Option<&'v Value>, ref_context: Context<'v>) -> ErrorIterator<'v>>

Get the validator object for the draft in use.

Source

pub fn get_format_checker( &self, key: &str, ) -> Option<fn(cfg: &Config<'_>, value: &str) -> bool>

Get the string format checker for the draft in use.

Source

pub fn get_draft_number(&self) -> u8

Get the draft number in use.

Source

pub fn get_metaschema(&self) -> &Value

Get the metaschema associated with the draft in use.

Source

pub fn get_resolver(&self) -> &Resolver<'a>

Get the resolver for the parsing context.

Source

pub fn get_schema(&self) -> &Value

Get the schema currently being checked against.

Source

pub fn from_schema( schema: &'a Value, draft: Option<Draft>, ) -> Result<Config<'a>, ValidationError>

Create a new Config object from a given schema.

Will use the Draft of JSON schema specified by draft. If draft is None, it will be automatically determined from the $schema entry in the given schema. If no $schema entry is present Draft 7 will be used by default.

Source

pub fn validate(&'a self, instance: &'a Value) -> Result<(), ErrorIterator<'a>>

Validate the given JSON instance against the schema.

Examples found in repository?
examples/threaded.rs (line 16)
13fn main() {
14    {
15        let data = serde_json::from_str("{}").unwrap();
16        assert!(SCHEMA_CFG.validate(&data).is_ok());
17    }
18
19    std::thread::spawn(|| {
20        let data = serde_json::from_str("{}").unwrap();
21        assert!(SCHEMA_CFG.validate(&data).is_ok());
22    });
23}
Source

pub fn validate_schema(&'a self) -> Result<(), ErrorIterator<'a>>

Validate the schema in this Config object against the metaschema.

Auto Trait Implementations§

§

impl<'a> Freeze for Config<'a>

§

impl<'a> RefUnwindSafe for Config<'a>

§

impl<'a> Send for Config<'a>

§

impl<'a> Sync for Config<'a>

§

impl<'a> Unpin for Config<'a>

§

impl<'a> UnwindSafe for Config<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.