File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -262,6 +262,9 @@ impl OwnedAsciiCast<[u8]> for Vec<u8> {
262
262
pub trait AsciiStr for Sized ? {
263
263
/// Convert to a string.
264
264
fn as_str < ' a > ( & ' a self ) -> & ' a str ;
265
+
266
+ /// Convert to bytes.
267
+ fn as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
265
268
}
266
269
267
270
#[ experimental = "may be replaced by generic conversion traits" ]
@@ -270,6 +273,11 @@ impl AsciiStr for [Ascii] {
270
273
fn as_str < ' a > ( & ' a self ) -> & ' a str {
271
274
unsafe { mem:: transmute ( self ) }
272
275
}
276
+
277
+ #[ inline]
278
+ fn as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
279
+ unsafe { mem:: transmute ( self ) }
280
+ }
273
281
}
274
282
275
283
impl IntoString for Vec < Ascii > {
@@ -356,6 +364,12 @@ mod tests {
356
364
assert_eq ! ( v. as_str( ) , "( ;" ) ;
357
365
}
358
366
367
+ #[ test]
368
+ fn test_ascii_as_bytes ( ) {
369
+ let v = v2ascii ! ( [ 40 , 32 , 59 ] ) ;
370
+ assert_eq ! ( v. as_bytes( ) , b"( ;" ) ;
371
+ }
372
+
359
373
#[ test]
360
374
fn test_ascii_into_string ( ) {
361
375
assert_eq ! ( vec2ascii![ 40 , 32 , 59 ] . into_string( ) , "( ;" . to_string( ) ) ;
You can’t perform that action at this time.
0 commit comments