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