1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use std::sync::Arc;
use iron_shapes::point::Deref;
use std::borrow::Borrow;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RcString {
string: Arc<String>
}
impl std::fmt::Display for RcString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.string.as_str(), f)
}
}
impl RcString {
pub fn new(string: String) -> Self {
RcString { string: Arc::new(string) }
}
}
impl Hash for RcString {
fn hash<H: Hasher>(&self, state: &mut H) {
self.string.hash(state)
}
}
impl Deref for RcString {
type Target = String;
fn deref(&self) -> &Self::Target {
self.string.deref()
}
}
impl Borrow<str> for RcString {
fn borrow(&self) -> &str {
self.as_str()
}
}
impl Borrow<String> for RcString {
fn borrow(&self) -> &String {
self.string.deref()
}
}
impl From<String> for RcString {
fn from(string: String) -> Self {
Self::new(string)
}
}
impl From<Arc<String>> for RcString {
fn from(string: Arc<String>) -> Self {
Self { string }
}
}
impl From<&Arc<String>> for RcString {
fn from(string: &Arc<String>) -> Self {
Self { string: string.clone() }
}
}
impl From<&str> for RcString {
fn from(s: &str) -> Self {
Self::new(s.to_string())
}
}
impl Into<String> for RcString {
fn into(self) -> String {
self.string.to_string()
}
}