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
use std::fmt::{Display, Formatter};
use crate::imp::structs::util::identity_equal_trait::IdentityEqual;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)]
pub struct RustString{
str : Arc<String>,
}
impl RustString{
pub fn new(s : String) -> RustString{ RustString{ str : Arc::new(s) } }
pub fn str(&self) -> &str{ self.str.as_ref().as_str() }
pub fn str_mut(&mut self) -> &mut str{ self.string_mut().as_mut_str() }
pub fn string(&self) -> &String{ self.str.as_ref() }
pub fn string_mut(&mut self) -> &mut String{ Arc::make_mut(&mut self.str) }
}
impl Display for RustString{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.str().fmt(f)
}
}
impl IdentityEqual for RustString{
fn identity_eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.str, &other.str)
}
}