ocpi_tariffs/
lint.rs

1//! Both tariffs and CDRs can be linted - a term borrowed from software development where
2//! linting is the act of flagging common errors, bugs, dangerous constructs and
3//! stylistic flaws in a some code or data.
4//!
5//! The term originates from the English word `lint`, the tiny pieces of fiber and fluff that are
6//! shed by clothing and trapped in a washing machines filter.
7//!
8//! Use [`tariff::lint`](crate::tariff::lint) to lint a tariff.
9
10pub mod tariff;
11
12use std::fmt;
13
14use crate::json;
15
16/// Lint the given tariff and return a report of any `Warning`s found.
17pub(crate) fn tariff(tariff: &crate::tariff::Versioned<'_>) -> Result<tariff::Report, Error> {
18    tariff::lint(tariff)
19}
20
21/// Possible errors when linting a tariff.
22#[derive(Debug)]
23pub enum Error {
24    /// An error occurred while parsing a `CDR` or tariff.
25    Parse(json::Error),
26}
27
28impl From<json::Error> for Error {
29    fn from(err: json::Error) -> Self {
30        Self::Parse(err)
31    }
32}
33
34impl std::error::Error for Error {
35    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
36        None
37    }
38}
39
40impl fmt::Display for Error {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            Error::Parse(err) => write!(f, "{err}"),
44        }
45    }
46}
47
48#[cfg(test)]
49mod test {
50    use super::Error;
51
52    #[test]
53    const fn error_should_be_send_and_sync() {
54        const fn f<T: Send + Sync>() {}
55
56        f::<Error>();
57    }
58}