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
use std::fmt::{self, Display};

use std::borrow::Cow;

use Fail;

pub fn error_msg<S: Into<Cow<'static, str>>>(msg: S) -> ErrorMessage {
    ErrorMessage { msg: msg.into() }
}

#[derive(Debug)]
pub struct ErrorMessage {
    msg: Cow<'static, str>,
}

impl Fail for ErrorMessage {
    fn fail(&self, f: &mut fmt::Formatter) -> fmt::Result {
        Display::fmt(&self.msg, f)
    }
}

#[macro_export]
macro_rules! format_err {
    ($($arg:tt)*) => { $crate::error_msg(format!($($arg)*)) }
}