ocpi-tariffs 0.43.0

OCPI tariff calculations
Documentation
#[cfg(test)]
mod test_real_world;

#[cfg(test)]
mod test_lints;

use tracing::instrument;

use crate::{
    json::{self, FieldsAsExt as _},
    required_field,
    warning::{self, DeescalateError, GatherWarnings as _},
};

use super::{v2x, Report, Warning};

#[instrument(skip_all)]
pub(crate) fn lint<'buf>(
    tariff_elem: &json::Element<'buf>,
    mut warnings: warning::Set<Warning>,
) -> Report {
    let Some(fields) = tariff_elem.as_object_fields() else {
        return Report { warnings };
    };

    let fields = fields.as_raw_map();

    if let Some(elem) = required_field!(tariff_elem, fields, "currency", warnings) {
        let _drop: Option<()> = v2x::currency::lint(elem)
            .gather_warnings_into(&mut warnings)
            .deescalate_error_into(&mut warnings);
    }

    {
        if let Some(elem) = required_field!(tariff_elem, fields, "elements", warnings) {
            let _drop: Option<()> = v2x::elements::lint(elem)
                .gather_warnings_into(&mut warnings)
                .deescalate_error_into(&mut warnings);
        }
    }

    Report { warnings }
}