1use ebacktrace::define_error;
2use std::{
3 error, io, result,
4 fmt::{ self, Display, Formatter }
5};
6
7
8#[macro_export] macro_rules! e {
10 ($kind:expr, $($arg:tt)*) => ({ $crate::error::ErrorImpl::new($kind, format!($($arg)*)) })
11}
12#[macro_export] macro_rules! eio {
14 ($($arg:tt)*) => ({ e!($crate::error::ErrorKind::InOutError, $($arg)*) });
15}
16#[macro_export] macro_rules! einval {
18 ($($arg:tt)*) => ({ e!($crate::error::ErrorKind::InvalidValue, $($arg)*) });
19}
20
21
22#[derive(Debug, PartialEq, Eq)]
24pub enum ErrorKind {
25 InOutError,
27 InvalidValue
29}
30impl Display for ErrorKind {
31 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
32 match self {
33 Self::InOutError => write!(f, "An I/O-error occurred"),
34 Self::InvalidValue => write!(f, "A value is invalid")
35 }
36 }
37}
38impl error::Error for ErrorKind {
39 }
41
42
43define_error!(ErrorImpl);
45impl From<io::Error> for ErrorImpl<ErrorKind> {
46 fn from(underlying: io::Error) -> Self {
47 ErrorImpl::new(ErrorKind::InOutError, underlying.to_string())
48 }
49}
50
51
52pub type Error = ErrorImpl<ErrorKind>;
54pub type Result<T = ()> = result::Result<T, ErrorImpl<ErrorKind>>;