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 core::cmp::Ordering;
pub trait BoxedString {
fn string(&self) -> &String;
fn string_mut(&mut self) -> &mut String;
fn into_string(self) -> String;
fn cmp_with_str(&self, other: &str) -> Ordering;
fn cmp_with_self(&self, other: &Self) -> Ordering;
fn eq_with_str(&self, other: &str) -> bool;
fn eq_with_self(&self, other: &Self) -> bool;
fn len(&self) -> usize {
self.string().len()
}
}
impl BoxedString for String {
#[inline(always)]
fn string(&self) -> &String {
self
}
#[inline(always)]
fn string_mut(&mut self) -> &mut String {
self
}
fn into_string(self) -> String {
self
}
#[inline(always)]
fn cmp_with_str(&self, other: &str) -> Ordering {
self.as_str().cmp(other)
}
#[inline(always)]
fn cmp_with_self(&self, other: &Self) -> Ordering {
self.cmp(other)
}
#[inline(always)]
fn eq_with_str(&self, other: &str) -> bool {
self == other
}
#[inline(always)]
fn eq_with_self(&self, other: &Self) -> bool {
self == other
}
}