@@ -29,16 +29,10 @@ mod my_ascii {
2929 fn from ( ascii : Ascii ) -> String {
3030 // If this module has no bugs, this is safe, because
3131 // well-formed ASCII text is also well-formed UTF-8.
32- unsafe {
33- String :: from_utf8_unchecked ( ascii. 0 )
34- }
32+ unsafe { String :: from_utf8_unchecked ( ascii. 0 ) }
3533 }
3634 }
3735
38- impl From < Ascii > for Vec < u8 > {
39- fn from ( ascii : Ascii ) -> Vec < u8 > { ascii. 0 }
40- }
41-
4236 // This must be placed inside the `my_ascii` module.
4337 impl Ascii {
4438 /// Construct an `Ascii` value from `bytes`, without checking
@@ -59,10 +53,9 @@ mod my_ascii {
5953 }
6054}
6155
62-
6356#[ test]
6457fn good_ascii ( ) {
65- use self :: my_ascii:: Ascii ;
58+ use my_ascii:: Ascii ;
6659
6760 let bytes: Vec < u8 > = b"ASCII and ye shall receive" . to_vec ( ) ;
6861
@@ -79,7 +72,7 @@ fn good_ascii() {
7972
8073#[ test]
8174fn bad_ascii ( ) {
82- use self :: my_ascii:: Ascii ;
75+ use my_ascii:: Ascii ;
8376
8477 // Imagine that this vector is the result of some complicated process
8578 // that we expected to produce ASCII. Something went wrong!
@@ -96,6 +89,5 @@ fn bad_ascii() {
9689 // `bogus` now holds ill-formed UTF-8. Parsing its first character produces
9790 // a `char` that is not a valid Unicode code point. That's undefined
9891 // behavior, so the language doesn't say how this assertion should behave.
99- // It could pass, fail, crash, do nothing at all, etc.
100- assert_eq ! ( bogus. chars( ) . next( ) . unwrap( ) as u32 , 0x1fffff_u32 ) ;
92+ assert_eq ! ( bogus. chars( ) . next( ) . unwrap( ) as u32 , 0x1fffff ) ;
10193}
0 commit comments