Struct jsonschema::output::Output

source ·
pub struct Output<'a, 'b> { /* private fields */ }
Expand description

The output format resulting from the application of a schema. This can be converted into various representations based on the definitions in https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.12.2

Currently only the “flag” and “basic” output formats are supported

Implementations§

source§

impl<'a, 'b> Output<'a, 'b>

source

pub fn flag(&self) -> bool

Indicates whether the schema was valid, corresponds to the “flag” output format

source

pub fn basic(&self) -> BasicOutput<'a>

Output a list of errors and annotations for each element in the schema according to the basic output format. BasicOutput implements serde::Serialize in a manner which conforms to the json core spec so one way to use this is to serialize the BasicOutput and examine the JSON which is produced. However, for rust programs this is not necessary. Instead you can match on the BasicOutput and examine the results. To use this API you’ll need to understand a few things:

Regardless of whether the the schema validation was successful or not the BasicOutput is a sequence of OutputUnits. An OutputUnit is some metadata about where the output is coming from (where in the schema and where in the instance). The difference between the BasicOutput::Valid and BasicOutput::Invalid cases is the value which is associated with each OutputUnit. For Valid outputs the value is an annotation, whilst for Invalid outputs it’s an ErrorDescription (a String really).

Examples
let output: BasicOutput = schema.apply(&instance).basic();
match output {
    BasicOutput::Valid(annotations) => {
        for annotation in annotations {
            println!(
                "Value: {} at path {}",
                annotation.value(),
                annotation.instance_location()
            )
        }
    },
    BasicOutput::Invalid(errors) => {
        for error in errors {
            println!(
                "Error: {} at path {}",
                error.error_description(),
                error.instance_location()
            )
        }
    }
}

Trait Implementations§

source§

impl<'a, 'b> Clone for Output<'a, 'b>

source§

fn clone(&self) -> Output<'a, 'b>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a, 'b> Debug for Output<'a, 'b>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'b> !RefUnwindSafe for Output<'a, 'b>

§

impl<'a, 'b> Send for Output<'a, 'b>

§

impl<'a, 'b> Sync for Output<'a, 'b>

§

impl<'a, 'b> Unpin for Output<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for Output<'a, 'b>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more