Skip to main content

multiscreen_rs/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4/// Result alias used by the crate.
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// Top-level crate error.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum Error {
10    Config(String),
11    Layout(String),
12    Training(String),
13    Inference(String),
14    /// File I/O failure.
15    Io(String),
16    /// Serialization or deserialization failure.
17    Serialization(String),
18    /// Weights file config does not match the engine config.
19    WeightsConfigMismatch(String),
20}
21
22impl fmt::Display for Error {
23    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::Config(message) => write!(formatter, "invalid configuration: {message}"),
26            Self::Layout(message) => write!(formatter, "layout error: {message}"),
27            Self::Training(message) => write!(formatter, "training error: {message}"),
28            Self::Inference(message) => write!(formatter, "inference error: {message}"),
29            Self::Io(message) => write!(formatter, "I/O error: {message}"),
30            Self::Serialization(message) => {
31                write!(formatter, "serialization error: {message}")
32            }
33            Self::WeightsConfigMismatch(message) => {
34                write!(formatter, "weights config mismatch: {message}")
35            }
36        }
37    }
38}
39
40impl StdError for Error {}