| 1 |
use std::borrow::Cow; |
| 2 |
use std::fmt::{Debug, Display, Formatter}; |
| 3 |
|
| 4 |
|
| 5 |
#[derive(Debug)] |
| 6 |
pub struct Message( |
| 7 |
|
| 8 |
pub(crate) Cow<'static, str>, |
| 9 |
); |
| 10 |
|
| 11 |
|
| 12 |
impl Message { |
| 13 |
|
| 14 |
pub fn new(message: impl Into<Cow<'static, str>>) -> Self { |
| 15 |
Message(message.into()) |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
impl Display for Message { |
| 20 |
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 21 |
f.write_str(self.0.as_ref()) |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
impl std::error::Error for Message {} |
| 26 |
|
| 27 |
impl From<String> for Message { |
| 28 |
fn from(msg: String) -> Self { |
| 29 |
Message::new(msg) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl From<&'static str> for Message { |
| 34 |
fn from(msg: &'static str) -> Self { |
| 35 |
Message::new(msg) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
pub fn message(message: &'static str) -> Message { |
| 43 |
Message::new(message) |
| 44 |
} |