forked from Nullus157/cbor-diag-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.rs
36 lines (29 loc) · 745 Bytes
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::{borrow::Cow, fmt};
#[derive(Debug)]
pub enum Error {
Todo(Cow<'static, str>),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<&'static str> for Error {
fn from(err: &'static str) -> Error {
Error::Todo(err.into())
}
}
impl From<String> for Error {
fn from(err: String) -> Error {
Error::Todo(err.into())
}
}
impl From<hex::FromHexError> for Error {
fn from(err: hex::FromHexError) -> Error {
err.to_string().into()
}
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Todo(s) => write!(f, "TODO cbor-diag::Error: {}", s),
}
}
}