alt_failure/
error_message.rs

1use core::fmt::{self, Display, Debug};
2
3use Fail;
4use Error;
5
6/// Constructs a `Fail` type from a string.
7///
8/// This is a convenient way to turn a string into an error value that
9/// can be passed around, if you do not want to create a new `Fail` type for
10/// this use case.
11pub fn err_msg<D: Display + Debug + Sync + Send + 'static>(msg: D) -> Error {
12    Error::from(ErrorMessage { msg })
13}
14
15/// A `Fail` type that just contains an error message. You can construct
16/// this from the `err_msg` function.
17#[derive(Debug)]
18struct ErrorMessage<D: Display + Debug + Sync + Send + 'static> {
19    msg: D,
20}
21
22impl<D: Display + Debug + Sync + Send + 'static> Fail for ErrorMessage<D> {
23    fn name(&self) -> Option<&str> {
24        Some("failure::ErrorMessage")
25    }
26}
27
28impl<D: Display + Debug + Sync + Send + 'static> Display for ErrorMessage<D> {
29    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30        Display::fmt(&self.msg, f)
31    }
32}