@@ -112,42 +112,42 @@ fn main() {
112112}
113113```
114114
115- Want a string that's not UTF-8? (Remember, ` str ` and ` String ` must be valid UTF-8)
115+ Want a string that's not UTF-8? (Remember, ` str ` and ` String ` must be valid UTF-8).
116116Or maybe you want an array of bytes that's mostly text? Byte strings to the rescue!
117117
118118``` rust, editable
119119use std::str;
120120
121121fn main() {
122- // Note that this is not actually a &str
123- let bytestring: &[u8; 20 ] = b"this is a bytestring ";
122+ // Note that this is not actually a ` &str`
123+ let bytestring: &[u8; 21 ] = b"this is a byte string ";
124124
125- // Byte arrays don't have Display so printing them is a bit limited
126- println!("A bytestring : {:?}", bytestring);
125+ // Byte arrays don't have the ` Display` trait, so printing them is a bit limited
126+ println!("A byte string : {:?}", bytestring);
127127
128- // Bytestrings can have byte escapes...
128+ // Byte strings can have byte escapes...
129129 let escaped = b"\x52\x75\x73\x74 as bytes";
130130 // ...but no unicode escapes
131131 // let escaped = b"\u{211D} is not allowed";
132132 println!("Some escaped bytes: {:?}", escaped);
133133
134134
135- // Raw bytestrings work just like raw strings
135+ // Raw byte strings work just like raw strings
136136 let raw_bytestring = br"\u{211D} is not escaped here";
137137 println!("{:?}", raw_bytestring);
138138
139- // Converting a byte array to str can fail
139+ // Converting a byte array to ` str` can fail
140140 if let Ok(my_str) = str::from_utf8(raw_bytestring) {
141141 println!("And the same as text: '{}'", my_str);
142142 }
143143
144- let quotes = br#"You can also use "fancier" formatting, \
144+ let _quotes = br#"You can also use "fancier" formatting, \
145145 like with normal raw strings"#;
146146
147- // Bytestrings don't have to be UTF-8
147+ // Byte strings don't have to be UTF-8
148148 let shift_jis = b"\x82\xe6\x82\xa8\x82\xb1\x82"; // "ようこそ" in SHIFT-JIS
149149
150- // But then they can't always be converted to str
150+ // But then they can't always be converted to ` str`
151151 match str::from_utf8(shift_jis) {
152152 Ok(my_str) => println!("Conversion successful: '{}'", my_str),
153153 Err(e) => println!("Conversion failed: {:?}", e),
0 commit comments