forbidden_bands/
error.rs

1//! Error types for working with 8-bit strings
2#![warn(missing_docs)]
3#![warn(unsafe_code)]
4
5use std::fmt::{Debug, Display, Formatter};
6
7/// The types of errors we can return
8pub enum ErrorKind {
9    /// Generic error type
10    // TODO: More error types
11    Message(String),
12}
13
14/// It's an error type, with tons of info
15pub struct Error {
16    kind: ErrorKind,
17}
18
19impl Display for Error {
20    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
21        match &self.kind {
22            ErrorKind::Message(m) => write!(f, "Some error occurred: {:?}", m),
23        }
24    }
25}
26
27impl Debug for Error {
28    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
29        write!(f, "{}", self)
30    }
31}
32
33impl From<serde_json::Error> for Error {
34    fn from(e: serde_json::Error) -> Self {
35        Error {
36            kind: ErrorKind::Message(e.to_string()),
37        }
38    }
39}
40
41impl From<std::io::Error> for Error {
42    fn from(e: std::io::Error) -> Self {
43        Error {
44            kind: ErrorKind::Message(e.to_string()),
45        }
46    }
47}