@@ -67,12 +67,14 @@ impl<'a> core::fmt::Debug for Reader<'a> {
67
67
}
68
68
69
69
impl < ' a > From < & ' a str > for Reader < ' a > {
70
+ #[ inline]
70
71
fn from ( value : & ' a str ) -> Self {
71
72
Self ( value. as_bytes ( ) )
72
73
}
73
74
}
74
75
75
76
impl < ' a > From < & ' a [ u8 ] > for Reader < ' a > {
77
+ #[ inline]
76
78
fn from ( value : & ' a [ u8 ] ) -> Self {
77
79
Self ( value)
78
80
}
@@ -103,27 +105,32 @@ impl<'a> crate::traits::FromPointerReader<'a> for Reader<'a> {
103
105
104
106
impl < ' a > Reader < ' a > {
105
107
/// The string's length, in bytes.
108
+ #[ inline]
106
109
pub fn len ( & self ) -> usize {
107
110
self . as_bytes ( ) . len ( )
108
111
}
109
112
113
+ #[ inline]
110
114
pub fn is_empty ( & self ) -> bool {
111
115
self . len ( ) == 0
112
116
}
113
117
118
+ #[ inline]
114
119
pub fn as_bytes ( self ) -> & ' a [ u8 ] {
115
120
let Self ( d) = self ;
116
121
d
117
122
}
118
123
119
124
/// Converts to a `str`, returning a error if the data contains invalid utf-8.
125
+ #[ inline]
120
126
pub fn to_str ( self ) -> core:: result:: Result < & ' a str , core:: str:: Utf8Error > {
121
127
let Self ( s) = self ;
122
128
str:: from_utf8 ( s)
123
129
}
124
130
125
131
#[ cfg( feature = "alloc" ) ]
126
132
/// Converts to a `String`, returning a error if the data contains invalid utf-8.
133
+ #[ inline]
127
134
pub fn to_string ( self ) -> core:: result:: Result < alloc:: string:: String , core:: str:: Utf8Error > {
128
135
Ok ( self . to_str ( ) ?. into ( ) )
129
136
}
@@ -156,50 +163,60 @@ impl<'a> core::cmp::PartialEq<Builder<'a>> for &'a str {
156
163
}
157
164
158
165
impl < ' a > Builder < ' a > {
166
+ #[ inline]
159
167
pub fn new ( bytes : & mut [ u8 ] ) -> Builder < ' _ > {
160
168
Builder { bytes, pos : 0 }
161
169
}
162
170
171
+ #[ inline]
163
172
pub fn with_pos ( bytes : & mut [ u8 ] , pos : usize ) -> Builder < ' _ > {
164
173
Builder { bytes, pos }
165
174
}
166
175
167
176
/// The string's length, in bytes.
177
+ #[ inline]
168
178
pub fn len ( & self ) -> usize {
169
179
self . bytes . len ( )
170
180
}
171
181
182
+ #[ inline]
172
183
pub fn is_empty ( & self ) -> bool {
173
184
self . len ( ) == 0
174
185
}
175
186
187
+ #[ inline]
176
188
pub fn as_bytes ( self ) -> & ' a [ u8 ] {
177
189
self . bytes
178
190
}
179
191
180
192
/// Converts to a `str`, returning a error if the data contains invalid utf-8.
193
+ #[ inline]
181
194
pub fn to_str ( self ) -> core:: result:: Result < & ' a str , core:: str:: Utf8Error > {
182
195
str:: from_utf8 ( self . bytes )
183
196
}
184
197
185
198
#[ cfg( feature = "alloc" ) ]
186
199
/// Converts to a `String`, returning a error if the data contains invalid utf-8.
200
+ #[ inline]
187
201
pub fn to_string ( self ) -> core:: result:: Result < alloc:: string:: String , core:: str:: Utf8Error > {
188
202
Ok ( self . to_str ( ) ?. into ( ) )
189
203
}
190
204
205
+ #[ inline]
191
206
pub fn as_bytes_mut ( self ) -> & ' a mut [ u8 ] {
192
207
& mut self . bytes [ ..]
193
208
}
194
209
195
210
/// Writes a single ascii character at position `pos` and increments `pos`.
211
+ #[ inline]
196
212
pub fn push_ascii ( & mut self , ascii : u8 ) {
197
213
assert ! ( ascii < 128 ) ;
198
214
self . bytes [ self . pos ] = ascii;
199
215
self . pos += 1 ;
200
216
}
201
217
202
218
/// Writes a string at position `pos` and increases `pos` a corresponding amount.
219
+ #[ inline]
203
220
pub fn push_str ( & mut self , string : & str ) {
204
221
let bytes = string. as_bytes ( ) ;
205
222
self . bytes [ self . pos ..( self . pos + bytes. len ( ) ) ] . copy_from_slice ( bytes) ;
@@ -214,17 +231,20 @@ impl<'a> Builder<'a> {
214
231
self . pos = 0 ;
215
232
}
216
233
234
+ #[ inline]
217
235
pub fn reborrow ( & mut self ) -> Builder < ' _ > {
218
236
Builder {
219
237
bytes : self . bytes ,
220
238
pos : self . pos ,
221
239
}
222
240
}
223
241
242
+ #[ inline]
224
243
pub fn into_reader ( self ) -> Reader < ' a > {
225
244
Reader ( self . bytes )
226
245
}
227
246
247
+ #[ inline]
228
248
pub fn reborrow_as_reader ( & self ) -> Reader < ' _ > {
229
249
Reader ( self . bytes )
230
250
}
0 commit comments