Skip to content

Commit 64472e4

Browse files
committed
Update ascii example.
1 parent 4880308 commit 64472e4

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

ascii/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
name = "ascii"
33
version = "0.1.0"
44
authors = ["You <[email protected]>"]
5+
edition = "2018"
56

67
[dependencies]

ascii/src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
6457
fn 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]
8174
fn 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

Comments
 (0)