han/
lib.rs

1//! No-std parser for the Swedish-Norwegian smart power meter customer interface
2//! called HAN or H1 (the latter was already registered on crates.io).
3
4#![warn(missing_docs)]
5#![no_std]
6
7mod obis;
8mod read;
9
10use core::fmt::Display;
11
12pub use obis::*;
13pub use read::*;
14
15/// HAN error.
16#[derive(Debug)]
17pub enum Error {
18    /// Parsing failed due to an invalid format.
19    InvalidFormat,
20    /// Checksum mismatch.
21    Checksum,
22    /// The parser came across a correctly formatted, but unrecognized,
23    /// [`Obis`] reference.
24    UnrecognizedReference,
25}
26
27impl Display for Error {
28    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
29        let msg = match self {
30            Error::InvalidFormat => "invalid format",
31            Error::Checksum => "checksum mismatch",
32            Error::UnrecognizedReference => "unrecognized obis reference",
33        };
34
35        f.write_str(msg)
36    }
37}
38
39pub(crate) type Result<T, E = Error> = core::result::Result<T, E>;