fast_str/backend/
normal.rs1use crate::normal::NormalString;
2
3#[repr(transparent)]
4#[derive(Clone)]
5pub struct FastStr(NormalString);
6
7#[allow(unused)]
8impl FastStr {
9 #[inline]
10 pub(super) fn do_sub_with<
11 'a,
12 R: 'a,
13 F: FnOnce(&'a str, Box<dyn Fn(&str) -> Self + 'a>) -> R,
14 >(
15 &'a self,
16 f: F,
17 ) -> R {
18 f(self.0.str, Box::new(|str| Self(self.0.map_ref(str))))
19 }
20
21 #[inline]
22 pub(super) fn do_sub_into<F: FnOnce(&str) -> &str>(self, f: F) -> Self {
23 let str = f(self.0.str);
24 Self(self.0.map_ref_into(str))
25 }
26
27 #[inline]
29 pub const fn new() -> Self {
30 Self::from_static("")
31 }
32
33 #[inline]
35 pub const fn from_static(str: &'static str) -> Self {
36 Self(NormalString::from_static(str))
37 }
38
39 #[inline]
41 pub fn from_string(str: String) -> Self {
42 Self(NormalString::from_string(str))
43 }
44
45 #[inline]
47 pub fn from_ref(str: &str) -> Self {
48 Self(NormalString::from_string(str.into()))
49 }
50
51 #[inline]
53 pub fn into_string(self) -> String {
54 self.0.into_string()
55 }
56
57 #[inline]
59 pub fn as_str(&self) -> &str {
60 self.0.as_str()
61 }
62
63 #[inline]
65 pub fn is_static(&self) -> bool {
66 self.0.is_static()
67 }
68
69 #[inline]
70 pub fn static_str(&self) -> Option<&'static str> {
71 self.0.static_str()
72 }
73}