From 935c57611f26f2b395528488d494e8bf1455ee77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:23:46 +0200 Subject: [PATCH 1/6] Add missing period. --- src/std/str.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/str.md b/src/std/str.md index a771d0613a..76870d9829 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -112,7 +112,7 @@ fn main() { } ``` -Want a string that's not UTF-8? (Remember, `str` and `String` must be valid UTF-8) +Want a string that's not UTF-8? (Remember, `str` and `String` must be valid UTF-8). Or maybe you want an array of bytes that's mostly text? Byte strings to the rescue! ```rust, editable From c94a6925277bdc678191bb7873e7a0d75cd3388f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:27:31 +0200 Subject: [PATCH 2/6] Reword a comment for clarity. --- src/std/str.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/str.md b/src/std/str.md index 76870d9829..776e186304 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -122,7 +122,7 @@ fn main() { // Note that this is not actually a &str let bytestring: &[u8; 20] = b"this is a bytestring"; - // Byte arrays don't have Display so printing them is a bit limited + // Byte arrays don't have the `Display` trait, so printing them is a bit limited println!("A bytestring: {:?}", bytestring); // Bytestrings can have byte escapes... From 9fbcf16bc85e476cdf2af62800400b6852059e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:32:37 +0200 Subject: [PATCH 3/6] Add missing quotes for the types in comments. --- src/std/str.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/std/str.md b/src/std/str.md index 776e186304..ed963d9649 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -119,7 +119,7 @@ Or maybe you want an array of bytes that's mostly text? Byte strings to the resc use std::str; fn main() { - // Note that this is not actually a &str + // Note that this is not actually a `&str` let bytestring: &[u8; 20] = b"this is a bytestring"; // Byte arrays don't have the `Display` trait, so printing them is a bit limited @@ -136,7 +136,7 @@ fn main() { let raw_bytestring = br"\u{211D} is not escaped here"; println!("{:?}", raw_bytestring); - // Converting a byte array to str can fail + // Converting a byte array to `str` can fail if let Ok(my_str) = str::from_utf8(raw_bytestring) { println!("And the same as text: '{}'", my_str); } @@ -147,7 +147,7 @@ fn main() { // Bytestrings don't have to be UTF-8 let shift_jis = b"\x82\xe6\x82\xa8\x82\xb1\x82"; // "ようこそ" in SHIFT-JIS - // But then they can't always be converted to str + // But then they can't always be converted to `str` match str::from_utf8(shift_jis) { Ok(my_str) => println!("Conversion successful: '{}'", my_str), Err(e) => println!("Conversion failed: {:?}", e), From ff273c4e7ad456b0f890c264d1f1d36c829a4764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:34:53 +0200 Subject: [PATCH 4/6] Fix inconsistend use of the `byte string` phrase. I have changed all instances of `bytestring` into `byte string`. The latter form seems to be the proper one. Language documentation also use `byte slice` naming, but I'm not sure it's a reference to the same thing, so I'm open to feedback from the community. --- src/std/str.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/std/str.md b/src/std/str.md index ed963d9649..5d366eea88 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -120,19 +120,19 @@ use std::str; fn main() { // Note that this is not actually a `&str` - let bytestring: &[u8; 20] = b"this is a bytestring"; + let bytestring: &[u8; 20] = b"this is a byte string"; // Byte arrays don't have the `Display` trait, so printing them is a bit limited - println!("A bytestring: {:?}", bytestring); + println!("A byte string: {:?}", bytestring); - // Bytestrings can have byte escapes... + // Byte strings can have byte escapes... let escaped = b"\x52\x75\x73\x74 as bytes"; // ...but no unicode escapes // let escaped = b"\u{211D} is not allowed"; println!("Some escaped bytes: {:?}", escaped); - // Raw bytestrings work just like raw strings + // Raw byte strings work just like raw strings let raw_bytestring = br"\u{211D} is not escaped here"; println!("{:?}", raw_bytestring); @@ -144,7 +144,7 @@ fn main() { let quotes = br#"You can also use "fancier" formatting, \ like with normal raw strings"#; - // Bytestrings don't have to be UTF-8 + // Byte strings don't have to be UTF-8 let shift_jis = b"\x82\xe6\x82\xa8\x82\xb1\x82"; // "ようこそ" in SHIFT-JIS // But then they can't always be converted to `str` From 44080b75fcc232031ff5bc1e2c15562a024278c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:45:23 +0200 Subject: [PATCH 5/6] Add `_` prefix to the unused variable name. --- src/std/str.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/str.md b/src/std/str.md index 5d366eea88..24e0cfc592 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -141,7 +141,7 @@ fn main() { println!("And the same as text: '{}'", my_str); } - let quotes = br#"You can also use "fancier" formatting, \ + let _quotes = br#"You can also use "fancier" formatting, \ like with normal raw strings"#; // Byte strings don't have to be UTF-8 From 94e91756b216a13ab7d84f0ffb66f2f09df88d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Fri, 28 Jun 2019 15:46:16 +0200 Subject: [PATCH 6/6] Fix array size bug introduced in previous commit. After changing `bytestring` into `byte string` in one of the byte string literals, I forgot to adjust the array size to compensate for an extra space. --- src/std/str.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/str.md b/src/std/str.md index 24e0cfc592..9f4d7105e1 100644 --- a/src/std/str.md +++ b/src/std/str.md @@ -120,7 +120,7 @@ use std::str; fn main() { // Note that this is not actually a `&str` - let bytestring: &[u8; 20] = b"this is a byte string"; + let bytestring: &[u8; 21] = b"this is a byte string"; // Byte arrays don't have the `Display` trait, so printing them is a bit limited println!("A byte string: {:?}", bytestring);