@@ -24,44 +24,50 @@ impl Default for CheetahString {
24
24
}
25
25
26
26
impl From < String > for CheetahString {
27
+ #[ inline]
27
28
fn from ( s : String ) -> Self {
28
29
CheetahString :: from_string ( s)
29
30
}
30
31
}
31
32
32
33
impl From < Arc < String > > for CheetahString {
34
+ #[ inline]
33
35
fn from ( s : Arc < String > ) -> Self {
34
36
CheetahString :: from_arc_string ( s)
35
37
}
36
38
}
37
39
38
40
impl < ' a > From < & ' a str > for CheetahString {
41
+ #[ inline]
39
42
fn from ( s : & ' a str ) -> Self {
40
43
CheetahString :: from_slice ( s)
41
44
}
42
45
}
43
46
44
47
impl From < & [ u8 ] > for CheetahString {
48
+ #[ inline]
45
49
fn from ( b : & [ u8 ] ) -> Self {
46
50
CheetahString :: from_slice ( unsafe { std:: str:: from_utf8_unchecked ( b) } )
47
51
}
48
52
}
49
53
50
54
impl FromStr for CheetahString {
51
55
type Err = std:: string:: ParseError ;
52
-
56
+ # [ inline ]
53
57
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
54
58
Ok ( CheetahString :: from_slice ( s) )
55
59
}
56
60
}
57
61
58
62
impl From < Vec < u8 > > for CheetahString {
63
+ #[ inline]
59
64
fn from ( v : Vec < u8 > ) -> Self {
60
65
CheetahString :: from_slice ( unsafe { std:: str:: from_utf8_unchecked ( & v) } )
61
66
}
62
67
}
63
68
64
69
impl From < Cow < ' static , str > > for CheetahString {
70
+ #[ inline]
65
71
fn from ( cow : Cow < ' static , str > ) -> Self {
66
72
match cow {
67
73
Cow :: Borrowed ( s) => CheetahString :: from_static_str ( s) ,
@@ -71,6 +77,7 @@ impl From<Cow<'static, str>> for CheetahString {
71
77
}
72
78
73
79
impl From < Cow < ' _ , String > > for CheetahString {
80
+ #[ inline]
74
81
fn from ( cow : Cow < ' _ , String > ) -> Self {
75
82
match cow {
76
83
Cow :: Borrowed ( s) => CheetahString :: from_slice ( s) ,
@@ -79,14 +86,66 @@ impl From<Cow<'_, String>> for CheetahString {
79
86
}
80
87
}
81
88
89
+ impl From < char > for CheetahString {
90
+ /// Allocates an owned [`CheetahString`] from a single character.
91
+ ///
92
+ /// # Example
93
+ /// ```rust
94
+ /// use cheetah_string::CheetahString;
95
+ /// let c: char = 'a';
96
+ /// let s: CheetahString = CheetahString::from(c);
97
+ /// assert_eq!("a", &s[..]);
98
+ /// ```
99
+ #[ inline]
100
+ fn from ( c : char ) -> Self {
101
+ CheetahString :: from_string ( c. to_string ( ) )
102
+ }
103
+ }
104
+
105
+ impl < ' a > FromIterator < & ' a char > for CheetahString {
106
+ fn from_iter < T : IntoIterator < Item = & ' a char > > ( iter : T ) -> CheetahString {
107
+ let mut buf = String :: new ( ) ;
108
+ buf. extend ( iter) ;
109
+ CheetahString :: from_string ( buf)
110
+ }
111
+ }
112
+
113
+ impl < ' a > FromIterator < & ' a str > for CheetahString {
114
+ fn from_iter < I : IntoIterator < Item = & ' a str > > ( iter : I ) -> CheetahString {
115
+ let mut buf = String :: new ( ) ;
116
+ buf. extend ( iter) ;
117
+ CheetahString :: from_string ( buf)
118
+ }
119
+ }
120
+
121
+ impl FromIterator < String > for CheetahString {
122
+ #[ inline]
123
+ fn from_iter < T : IntoIterator < Item = String > > ( iter : T ) -> Self {
124
+ let mut buf = String :: new ( ) ;
125
+ buf. extend ( iter) ;
126
+ CheetahString :: from_string ( buf)
127
+ }
128
+ }
129
+
130
+ impl < ' a > FromIterator < & ' a String > for CheetahString {
131
+ #[ inline]
132
+ fn from_iter < T : IntoIterator < Item = & ' a String > > ( iter : T ) -> Self {
133
+ let mut buf = String :: new ( ) ;
134
+ buf. extend ( iter. into_iter ( ) . map ( |s| s. as_str ( ) ) ) ;
135
+ CheetahString :: from_string ( buf)
136
+ }
137
+ }
138
+
82
139
#[ cfg( feature = "bytes" ) ]
83
140
impl From < bytes:: Bytes > for CheetahString {
141
+ #[ inline]
84
142
fn from ( b : bytes:: Bytes ) -> Self {
85
143
CheetahString :: from_bytes ( b)
86
144
}
87
145
}
88
146
89
147
impl From < & CheetahString > for CheetahString {
148
+ #[ inline]
90
149
fn from ( s : & CheetahString ) -> Self {
91
150
s. clone ( )
92
151
}
0 commit comments