Context

Struct Context 

Source
pub struct Context<'schema> { /* private fields */ }
Expand description

Contains a number of schemas that may or may not be dependent on each other.

Implementations§

Source§

impl<'schema> Context<'schema>

Source

pub fn get_schema(&self, uri: &str) -> Option<&Schema<'schema>>

Get a reference to a single schema within the context to use for validation.

§Examples
let schemas = vec![
    YamlLoader::load_from_str(r#"
        uri: just-a-number
        schema:
            type: integer
    "#).unwrap().remove(0)
];

let context = Context::try_from(&schemas[..]).unwrap();
let document = YamlLoader::load_from_str("10").unwrap().remove(0);

context.get_schema("just-a-number").unwrap()
    .validate(&context, &document).unwrap();

Trait Implementations§

Source§

impl<'schema> Debug for Context<'schema>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'schema> Default for Context<'schema>

Source§

fn default() -> Context<'schema>

Returns the “default value” for a type. Read more
Source§

impl<'schema> TryFrom<&'schema [Yaml]> for Context<'schema>

A context can only be created from a vector of Yaml documents, all of which must fit the schema layout.

Source§

type Error = SchemaError<'schema>

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

fn try_from(documents: &'schema [Yaml]) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'schema> Freeze for Context<'schema>

§

impl<'schema> RefUnwindSafe for Context<'schema>

§

impl<'schema> Send for Context<'schema>

§

impl<'schema> Sync for Context<'schema>

§

impl<'schema> Unpin for Context<'schema>

§

impl<'schema> UnwindSafe for Context<'schema>

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.