@@ -147,7 +147,7 @@ impl<'a> fmt::Show for Ascii {
147
147
pub trait AsciiCast < T , U = Self > for Sized ?: AsciiExt < U > {
148
148
/// Convert to an ascii type, return None on non-ASCII input.
149
149
#[ inline]
150
- fn to_ascii_opt ( & self ) -> Option < T > {
150
+ fn to_ascii ( & self ) -> Option < T > {
151
151
if self . is_ascii ( ) {
152
152
Some ( unsafe { self . to_ascii_nocheck ( ) } )
153
153
} else {
@@ -197,7 +197,7 @@ pub trait OwnedAsciiCast<Sized? T, U = Self>
197
197
where T : BorrowFrom < Self > + AsciiExt < U > {
198
198
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input.
199
199
#[ inline]
200
- fn into_ascii_opt ( self ) -> Option < Vec < Ascii > > {
200
+ fn into_ascii ( self ) -> Option < Vec < Ascii > > {
201
201
if {
202
202
let borrowed: & T = BorrowFrom :: borrow_from ( & self ) ;
203
203
borrowed. is_ascii ( )
@@ -306,30 +306,30 @@ mod tests {
306
306
307
307
#[ test]
308
308
fn test_ascii ( ) {
309
- assert_eq ! ( 65u8 . to_ascii_opt ( ) . unwrap( ) . as_byte( ) , 65u8 ) ;
310
- assert_eq ! ( 65u8 . to_ascii_opt ( ) . unwrap( ) . as_char( ) , 'A' ) ;
311
- assert_eq ! ( 'A' . to_ascii_opt ( ) . unwrap( ) . as_char( ) , 'A' ) ;
312
- assert_eq ! ( 'A' . to_ascii_opt ( ) . unwrap( ) . as_byte( ) , 65u8 ) ;
309
+ assert_eq ! ( 65u8 . to_ascii ( ) . unwrap( ) . as_byte( ) , 65u8 ) ;
310
+ assert_eq ! ( 65u8 . to_ascii ( ) . unwrap( ) . as_char( ) , 'A' ) ;
311
+ assert_eq ! ( 'A' . to_ascii ( ) . unwrap( ) . as_char( ) , 'A' ) ;
312
+ assert_eq ! ( 'A' . to_ascii ( ) . unwrap( ) . as_byte( ) , 65u8 ) ;
313
313
314
- assert ! ( '0' . to_ascii_opt ( ) . unwrap( ) . is_digit( ) ) ;
315
- assert ! ( '9' . to_ascii_opt ( ) . unwrap( ) . is_digit( ) ) ;
316
- assert ! ( !'/' . to_ascii_opt ( ) . unwrap( ) . is_digit( ) ) ;
317
- assert ! ( !':' . to_ascii_opt ( ) . unwrap( ) . is_digit( ) ) ;
314
+ assert ! ( '0' . to_ascii ( ) . unwrap( ) . is_digit( ) ) ;
315
+ assert ! ( '9' . to_ascii ( ) . unwrap( ) . is_digit( ) ) ;
316
+ assert ! ( !'/' . to_ascii ( ) . unwrap( ) . is_digit( ) ) ;
317
+ assert ! ( !':' . to_ascii ( ) . unwrap( ) . is_digit( ) ) ;
318
318
319
- assert ! ( ( 0x1fu8 ) . to_ascii_opt ( ) . unwrap( ) . is_control( ) ) ;
320
- assert ! ( !' ' . to_ascii_opt ( ) . unwrap( ) . is_control( ) ) ;
321
- assert ! ( ( 0x7fu8 ) . to_ascii_opt ( ) . unwrap( ) . is_control( ) ) ;
319
+ assert ! ( ( 0x1fu8 ) . to_ascii ( ) . unwrap( ) . is_control( ) ) ;
320
+ assert ! ( !' ' . to_ascii ( ) . unwrap( ) . is_control( ) ) ;
321
+ assert ! ( ( 0x7fu8 ) . to_ascii ( ) . unwrap( ) . is_control( ) ) ;
322
322
}
323
323
324
324
#[ test]
325
325
fn test_ascii_vec ( ) {
326
326
let test = & [ 40u8 , 32u8 , 59u8 ] ;
327
327
let b: & [ _ ] = v2ascii ! ( [ 40 , 32 , 59 ] ) ;
328
- assert_eq ! ( test. to_ascii_opt ( ) . unwrap( ) , b) ;
329
- assert_eq ! ( "( ;" . to_ascii_opt ( ) . unwrap( ) , b) ;
328
+ assert_eq ! ( test. to_ascii ( ) . unwrap( ) , b) ;
329
+ assert_eq ! ( "( ;" . to_ascii ( ) . unwrap( ) , b) ;
330
330
let v = vec ! [ 40u8 , 32u8 , 59u8 ] ;
331
- assert_eq ! ( v. as_slice( ) . to_ascii_opt ( ) . unwrap( ) , b) ;
332
- assert_eq ! ( "( ;" . to_string( ) . as_slice( ) . to_ascii_opt ( ) . unwrap( ) , b) ;
331
+ assert_eq ! ( v. as_slice( ) . to_ascii ( ) . unwrap( ) , b) ;
332
+ assert_eq ! ( "( ;" . to_string( ) . as_slice( ) . to_ascii ( ) . unwrap( ) , b) ;
333
333
}
334
334
335
335
#[ test]
@@ -357,32 +357,32 @@ mod tests {
357
357
358
358
#[ test]
359
359
fn test_opt ( ) {
360
- assert_eq ! ( 65u8 . to_ascii_opt ( ) , Some ( Ascii { chr: 65u8 } ) ) ;
361
- assert_eq ! ( 255u8 . to_ascii_opt ( ) , None ) ;
360
+ assert_eq ! ( 65u8 . to_ascii ( ) , Some ( Ascii { chr: 65u8 } ) ) ;
361
+ assert_eq ! ( 255u8 . to_ascii ( ) , None ) ;
362
362
363
- assert_eq ! ( 'A' . to_ascii_opt ( ) , Some ( Ascii { chr: 65u8 } ) ) ;
364
- assert_eq ! ( 'λ' . to_ascii_opt ( ) , None ) ;
363
+ assert_eq ! ( 'A' . to_ascii ( ) , Some ( Ascii { chr: 65u8 } ) ) ;
364
+ assert_eq ! ( 'λ' . to_ascii ( ) , None ) ;
365
365
366
- assert_eq ! ( "zoä华" . to_ascii_opt ( ) , None ) ;
366
+ assert_eq ! ( "zoä华" . to_ascii ( ) , None ) ;
367
367
368
368
let test1 = & [ 127u8 , 128u8 , 255u8 ] ;
369
- assert_eq ! ( ( test1) . to_ascii_opt ( ) , None ) ;
369
+ assert_eq ! ( ( test1) . to_ascii ( ) , None ) ;
370
370
371
371
let v = [ 40u8 , 32u8 , 59u8 ] ;
372
372
let v2: & [ _ ] = v2ascii ! ( & [ 40 , 32 , 59 ] ) ;
373
- assert_eq ! ( v. to_ascii_opt ( ) , Some ( v2) ) ;
373
+ assert_eq ! ( v. to_ascii ( ) , Some ( v2) ) ;
374
374
let v = [ 127u8 , 128u8 , 255u8 ] ;
375
- assert_eq ! ( v. to_ascii_opt ( ) , None ) ;
375
+ assert_eq ! ( v. to_ascii ( ) , None ) ;
376
376
377
377
let v = "( ;" ;
378
- assert_eq ! ( v. to_ascii_opt ( ) , Some ( v2) ) ;
379
- assert_eq ! ( "zoä华" . to_ascii_opt ( ) , None ) ;
378
+ assert_eq ! ( v. to_ascii ( ) , Some ( v2) ) ;
379
+ assert_eq ! ( "zoä华" . to_ascii ( ) , None ) ;
380
380
381
- assert_eq ! ( ( vec![ 40u8 , 32u8 , 59u8 ] ) . into_ascii_opt ( ) , Some ( vec2ascii![ 40 , 32 , 59 ] ) ) ;
382
- assert_eq ! ( ( vec![ 127u8 , 128u8 , 255u8 ] ) . into_ascii_opt ( ) , None ) ;
381
+ assert_eq ! ( ( vec![ 40u8 , 32u8 , 59u8 ] ) . into_ascii ( ) , Some ( vec2ascii![ 40 , 32 , 59 ] ) ) ;
382
+ assert_eq ! ( ( vec![ 127u8 , 128u8 , 255u8 ] ) . into_ascii ( ) , None ) ;
383
383
384
- assert_eq ! ( ( "( ;" . to_string( ) ) . into_ascii_opt ( ) , Some ( vec2ascii![ 40 , 32 , 59 ] ) ) ;
385
- assert_eq ! ( ( "zoä华" . to_string( ) ) . into_ascii_opt ( ) , None ) ;
384
+ assert_eq ! ( ( "( ;" . to_string( ) ) . into_ascii ( ) , Some ( vec2ascii![ 40 , 32 , 59 ] ) ) ;
385
+ assert_eq ! ( ( "zoä华" . to_string( ) ) . into_ascii ( ) , None ) ;
386
386
}
387
387
388
388
#[ test]
0 commit comments