@@ -145,13 +145,6 @@ impl<'a> fmt::Show for Ascii {
145
145
/// Trait for converting into an ascii type.
146
146
#[ experimental = "may be replaced by generic conversion traits" ]
147
147
pub trait AsciiCast < T , U = Self > for Sized ?: AsciiExt < U > {
148
- /// Convert to an ascii type, panic on non-ASCII input.
149
- #[ inline]
150
- fn to_ascii ( & self ) -> T {
151
- assert ! ( self . is_ascii( ) ) ;
152
- unsafe { self . to_ascii_nocheck ( ) }
153
- }
154
-
155
148
/// Convert to an ascii type, return None on non-ASCII input.
156
149
#[ inline]
157
150
fn to_ascii_opt ( & self ) -> Option < T > {
@@ -202,19 +195,6 @@ impl AsciiCast<Ascii> for char {
202
195
#[ experimental = "may be replaced by generic conversion traits" ]
203
196
pub trait OwnedAsciiCast < Sized ? T , U = Self >
204
197
where T : BorrowFrom < Self > + AsciiExt < U > {
205
- /// Take ownership and cast to an ascii vector.
206
- /// # Panics
207
- ///
208
- /// Panic on non-ASCII input.
209
- #[ inline]
210
- fn into_ascii ( self ) -> Vec < Ascii > {
211
- assert ! ( {
212
- let borrowed: & T = BorrowFrom :: borrow_from( & self ) ;
213
- borrowed. is_ascii( )
214
- } ) ;
215
- unsafe { self . into_ascii_nocheck ( ) }
216
- }
217
-
218
198
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input.
219
199
#[ inline]
220
200
fn into_ascii_opt ( self ) -> Option < Vec < Ascii > > {
@@ -326,36 +306,30 @@ mod tests {
326
306
327
307
#[ test]
328
308
fn test_ascii ( ) {
329
- assert_eq ! ( 65u8 . to_ascii ( ) . as_byte( ) , 65u8 ) ;
330
- assert_eq ! ( 65u8 . to_ascii ( ) . as_char( ) , 'A' ) ;
331
- assert_eq ! ( 'A' . to_ascii ( ) . as_char( ) , 'A' ) ;
332
- assert_eq ! ( 'A' . to_ascii ( ) . as_byte( ) , 65u8 ) ;
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 ) ;
333
313
334
- assert ! ( '0' . to_ascii ( ) . is_digit( ) ) ;
335
- assert ! ( '9' . to_ascii ( ) . is_digit( ) ) ;
336
- assert ! ( !'/' . to_ascii ( ) . is_digit( ) ) ;
337
- assert ! ( !':' . to_ascii ( ) . is_digit( ) ) ;
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( ) ) ;
338
318
339
- assert ! ( ( 0x1fu8 ) . to_ascii ( ) . is_control( ) ) ;
340
- assert ! ( !' ' . to_ascii ( ) . is_control( ) ) ;
341
- assert ! ( ( 0x7fu8 ) . to_ascii ( ) . is_control( ) ) ;
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( ) ) ;
342
322
}
343
323
344
324
#[ test]
345
325
fn test_ascii_vec ( ) {
346
326
let test = & [ 40u8 , 32u8 , 59u8 ] ;
347
327
let b: & [ _ ] = v2ascii ! ( [ 40 , 32 , 59 ] ) ;
348
- assert_eq ! ( test. to_ascii ( ) , b) ;
349
- assert_eq ! ( "( ;" . to_ascii ( ) , b) ;
328
+ assert_eq ! ( test. to_ascii_opt ( ) . unwrap ( ) , b) ;
329
+ assert_eq ! ( "( ;" . to_ascii_opt ( ) . unwrap ( ) , b) ;
350
330
let v = vec ! [ 40u8 , 32u8 , 59u8 ] ;
351
- assert_eq ! ( v. as_slice( ) . to_ascii( ) , b) ;
352
- assert_eq ! ( "( ;" . to_string( ) . as_slice( ) . to_ascii( ) , b) ;
353
- }
354
-
355
- #[ test]
356
- fn test_owned_ascii_vec ( ) {
357
- assert_eq ! ( ( "( ;" . to_string( ) ) . into_ascii( ) , vec2ascii![ 40 , 32 , 59 ] ) ;
358
- assert_eq ! ( ( vec![ 40u8 , 32u8 , 59u8 ] ) . into_ascii( ) , vec2ascii![ 40 , 32 , 59 ] ) ;
331
+ assert_eq ! ( v. as_slice( ) . to_ascii_opt( ) . unwrap( ) , b) ;
332
+ assert_eq ! ( "( ;" . to_string( ) . as_slice( ) . to_ascii_opt( ) . unwrap( ) , b) ;
359
333
}
360
334
361
335
#[ test]
@@ -381,18 +355,6 @@ mod tests {
381
355
assert_eq ! ( vec2ascii![ 40 , 32 , 59 ] . into_bytes( ) , vec![ 40u8 , 32u8 , 59u8 ] ) ;
382
356
}
383
357
384
- #[ test] #[ should_fail]
385
- fn test_ascii_vec_panic_u8_slice ( ) { ( & [ 127u8 , 128u8 , 255u8 ] ) . to_ascii ( ) ; }
386
-
387
- #[ test] #[ should_fail]
388
- fn test_ascii_vec_panic_str_slice ( ) { "zoä华" . to_ascii ( ) ; }
389
-
390
- #[ test] #[ should_fail]
391
- fn test_ascii_panic_u8_slice ( ) { 255u8 . to_ascii ( ) ; }
392
-
393
- #[ test] #[ should_fail]
394
- fn test_ascii_panic_char_slice ( ) { 'λ' . to_ascii ( ) ; }
395
-
396
358
#[ test]
397
359
fn test_opt ( ) {
398
360
assert_eq ! ( 65u8 . to_ascii_opt( ) , Some ( Ascii { chr: 65u8 } ) ) ;
0 commit comments