1use core::{
2 borrow::{Borrow, BorrowMut},
3 ops::{Deref, DerefMut},
4};
5use derive_more::{Display, From, Into};
6
7#[derive(Debug, Display, Clone, From, Into, PartialEq, Eq, PartialOrd, Ord)]
9pub struct Text(Box<str>);
10
11impl Text {
12 pub fn as_str(&self) -> &str {
14 self
15 }
16}
17
18impl From<String> for Text {
19 fn from(value: String) -> Self {
20 value.into_boxed_str().into()
21 }
22}
23
24impl From<Text> for String {
25 fn from(value: Text) -> Self {
26 value.0.into()
27 }
28}
29
30impl<'a> From<&'a str> for Text {
31 fn from(value: &'a str) -> Self {
32 value.to_string().into()
33 }
34}
35
36impl AsRef<str> for Text {
37 fn as_ref(&self) -> &str {
38 self
39 }
40}
41
42impl AsMut<str> for Text {
43 fn as_mut(&mut self) -> &mut str {
44 self
45 }
46}
47
48impl Borrow<str> for Text {
49 fn borrow(&self) -> &str {
50 self
51 }
52}
53
54impl BorrowMut<str> for Text {
55 fn borrow_mut(&mut self) -> &mut str {
56 self
57 }
58}
59
60impl Deref for Text {
61 type Target = str;
62 fn deref(&self) -> &Self::Target {
63 &self.0
64 }
65}
66
67impl DerefMut for Text {
68 fn deref_mut(&mut self) -> &mut Self::Target {
69 &mut self.0
70 }
71}