1use iron_shapes::point::Deref;
29use std::borrow::Borrow;
30use std::hash::{Hash, Hasher};
31use std::sync::Arc;
32
33#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
36#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
37pub struct RcString {
38 string: Arc<String>,
39}
40
41impl std::fmt::Display for RcString {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 std::fmt::Display::fmt(self.string.as_str(), f)
44 }
45}
46
47impl RcString {
48 pub fn new(string: String) -> Self {
50 RcString {
51 string: Arc::new(string),
52 }
53 }
54}
55
56impl Hash for RcString {
57 fn hash<H: Hasher>(&self, state: &mut H) {
58 self.string.hash(state)
59 }
60}
61
62impl Deref for RcString {
63 type Target = String;
64
65 fn deref(&self) -> &Self::Target {
66 self.string.deref()
67 }
68}
69
70impl Borrow<str> for RcString {
71 fn borrow(&self) -> &str {
72 self.as_str()
73 }
74}
75
76impl Borrow<String> for RcString {
77 fn borrow(&self) -> &String {
78 self.string.deref()
79 }
80}
81
82impl From<String> for RcString {
83 fn from(string: String) -> Self {
84 Self::new(string)
85 }
86}
87
88impl From<Arc<String>> for RcString {
89 fn from(string: Arc<String>) -> Self {
90 Self { string }
91 }
92}
93
94impl From<&Arc<String>> for RcString {
95 fn from(string: &Arc<String>) -> Self {
96 Self {
97 string: string.clone(),
98 }
99 }
100}
101
102impl From<&str> for RcString {
103 fn from(s: &str) -> Self {
104 Self::new(s.to_string())
105 }
106}
107
108impl From<RcString> for String {
109 fn from(val: RcString) -> Self {
110 val.string.to_string()
111 }
112}