ocpi-tariffs 0.20.0

OCPI tariff calculations
Documentation
//! Both tariffs and CDRs can be linted - a term borrowed from software development where
//! linting is the act of flagging common errors, bugs, dangerous constructs and
//! stylistic flaws in a some code or data.
//!
//! The term originates from the English word `lint`, the tiny pieces of fiber and fluff that are
//! shed by clothing and trapped in a washing machines filter.
//!
//! Use [`tariff::lint`](crate::tariff::lint) to lint a tariff.

pub mod tariff;

use std::fmt;

use crate::json;

/// Lint the given tariff and return a report of any `Warning`s found.
pub fn tariff(tariff: &crate::tariff::Versioned<'_>) -> Result<tariff::Report, Error> {
    tariff::lint(tariff)
}

/// Possible errors when linting a tariff.
#[derive(Debug)]
pub enum Error {
    /// An error occurred while parsing a `CDR` or tariff.
    Parse(json::Error),
}

impl From<json::Error> for Error {
    fn from(err: json::Error) -> Self {
        Self::Parse(err)
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        None
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Parse(err) => write!(f, "{err}"),
        }
    }
}

#[cfg(test)]
mod test {
    use super::Error;

    #[test]
    const fn error_should_be_send_and_sync() {
        const fn f<T: Send + Sync>() {}

        f::<Error>();
    }
}