use std::borrow::Cow;
use std::fmt::{Debug, Display, Formatter};
#[derive(Debug)]
pub struct Message(
pub(crate) Cow<'static, str>,
);
impl Message {
pub fn new(message: impl Into<Cow<'static, str>>) -> Self {
Message(message.into())
}
}
impl Display for Message {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(self.0.as_ref())
}
}
impl std::error::Error for Message {}
impl From<String> for Message {
fn from(msg: String) -> Self {
Message::new(msg)
}
}
impl From<&'static str> for Message {
fn from(msg: &'static str) -> Self {
Message::new(msg)
}
}
pub fn message(message: &'static str) -> Message {
Message::new(message)
}