fluent_static/
message.rs

1use std::{borrow::Cow, fmt::Display, ops::Deref};
2
3#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
4pub struct Message(pub(crate) Cow<'static, str>);
5
6impl Message {
7    pub const fn new(value: Cow<'static, str>) -> Self {
8        Self(value)
9    }
10}
11
12impl From<String> for Message {
13    fn from(value: String) -> Self {
14        Self::new(Cow::Owned(value))
15    }
16}
17
18impl Display for Message {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        f.write_str(&self.0)
21    }
22}
23
24impl Deref for Message {
25    type Target = str;
26
27    fn deref(&self) -> &Self::Target {
28        &*self.0
29    }
30}
31
32impl PartialEq<str> for Message {
33    fn eq(&self, other: &str) -> bool {
34        self.0 == other
35    }
36}
37
38impl PartialEq<Message> for str {
39    fn eq(&self, other: &Message) -> bool {
40        self == other.0
41    }
42}
43
44impl PartialEq<&str> for Message {
45    fn eq(&self, other: &&str) -> bool {
46        self.0 == *other
47    }
48}
49
50impl PartialEq<Message> for &str {
51    fn eq(&self, other: &Message) -> bool {
52        *self == other.0
53    }
54}