1use ebacktrace::define_error;
2use std::{
3 io, result,
4 fmt::{ self, Display, Formatter }
5};
6
7
8#[macro_export] macro_rules! e {
10 ($kind:expr, $($arg:tt)*) => ({ $crate::error::ErrorImpl::with_string($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}
38
39
40define_error!(ErrorImpl);
42impl From<io::Error> for ErrorImpl<ErrorKind> {
43 fn from(underlying: io::Error) -> Self {
44 ErrorImpl::with_string(ErrorKind::InOutError, underlying)
45 }
46}
47
48
49pub type Error = ErrorImpl<ErrorKind>;
51pub type Result<T = ()> = result::Result<T, ErrorImpl<ErrorKind>>;