Clarify that there isn't a separate "byte type"

The text indicated that there was separate a "byte type" in Rust.
However, based on the Rust reference, byte literals are simply a more
convenient way to represent `u8` numbers and arrays of `u8` numbers.
This change clarifies that there is no separate "byte type".

Also, the text suggested that only ASCII characters could be represented
with byte literals; however, non-ASCII 8-bit values can be represented
using backslash escapes in byte literals. This change changes the
wording to "8-bit values".
This commit is contained in:
Jim Turner 2016-08-20 17:33:59 -04:00
parent ba94ced602
commit a95ac62c80

View File

@ -168,7 +168,7 @@ about Unicode Scalar Values at
*http://www.unicode.org/glossary/#unicode_scalar_value* and find a chart for *http://www.unicode.org/glossary/#unicode_scalar_value* and find a chart for
all unicode code points at *http://www.unicode.org/charts/*. all unicode code points at *http://www.unicode.org/charts/*.
#### The Byte Type #### Byte Literals
You can work with the bytes of data directly. Byte literals can be created from You can work with the bytes of data directly. Byte literals can be created from
the ASCII characters using `b` and single quotes: the ASCII characters using `b` and single quotes:
@ -183,9 +183,14 @@ fn main() {
``` ```
This will print `byte is 97`. Similarly, byte string literals can be created This will print `byte is 97`. Similarly, byte string literals can be created
using `b` and double quotes, like `b"some byte string"`. Note that since you are using `b` and double quotes, like `b"some byte string"`.
limited to ASCII characters, it's a best practice to use characters instead of
bytes when you're working with natural language text. A byte literal is equivalent to a `u8` unsigned 8-bit integer *number literal*,
and a byte string literal of length `n` is equivalent to a `&'static [u8; n]`
borrowed fixed-sized array of unsigned 8-bit integers.
Note that since you are limited to 8-bit values, it's a best practice to use
characters instead of bytes when you're working with natural language text.
### Compound Types ### Compound Types