ocpi-tariffs 0.55.0

OCPI tariff calculations
Documentation
//! Test support for the schema walk.

use super::{LowerSchema, Schema, Warning, build};
use crate::{Caveat, Verdict, json, warning};

/// Walk `doc` against `schema`, returning the built node and the walk's warnings in a
/// [`Caveat`].
pub(super) fn walk<'buf>(
    doc: &json::Document<'buf>,
    schema: &Schema,
) -> Caveat<build::Node<'buf>, Warning> {
    let mut warnings = warning::Gatherer::new();
    let node = super::walk(doc, schema, &mut warnings);
    Caveat::new(node, warnings.into_set())
}

/// Convert a schema IR value on its own, for a test of one lowering.
///
/// Outside the tests, a lowering gathers its warnings into its caller's gatherer through
/// [`FromSchema::from_schema`](super::FromSchema::from_schema). A test of one lowering has no
/// caller, so `verdict_from_schema` gathers into a gatherer of its own and returns the outcome
/// and the warnings together as a [`Verdict`].
pub(crate) trait FromSchemaVerdict<'buf, Source>: LowerSchema<'buf, Source> {
    fn verdict_from_schema(source: &Source) -> Verdict<Self, Self::Warning>;
}

impl<'buf, Source, T> FromSchemaVerdict<'buf, Source> for T
where
    T: LowerSchema<'buf, Source>,
{
    fn verdict_from_schema(source: &Source) -> Verdict<Self, Self::Warning> {
        let mut warnings = warning::Gatherer::new();
        let value = Self::lower_schema(source, &mut warnings);
        warnings.into_verdict(value)
    }
}