mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-03 07:48:41 +08:00
Fix some spelling suggestions
This commit is contained in:
parent
b6ac0b9300
commit
86862b1c71
@ -16,7 +16,7 @@ let v: Vec<i32> = Vec::new();
|
||||
|
||||
Note that we added a type annotation here. Since we aren't inserting any values
|
||||
into this vector, Rust doesn't know what kind of elements we intend to store.
|
||||
This is an important point. Vectors are homogenous: they may store many values,
|
||||
This is an important point. Vectors are homogeneous: they may store many values,
|
||||
but those values must all be the same type. Vectors are implemented using
|
||||
generics, which Chapter 10 will cover how to use in your own types. For now,
|
||||
all you need to know is that the `Vec` type provided by the standard library
|
||||
|
@ -282,7 +282,7 @@ encoded in UTF-8, the first byte of `З` is `208`, and the second is `151`, so
|
||||
own. Returning `208` is likely not what a person would want if they asked for
|
||||
the first letter of this string, but that's the only data that Rust has at byte
|
||||
index 0. Returning the byte value is probably not what people want, even with
|
||||
only latin letters: `&"hello"[0]` would return `104`, not `h`. To avoid
|
||||
only Latin letters: `&"hello"[0]` would return `104`, not `h`. To avoid
|
||||
returning an unexpected value and causing bugs that might not be discovered
|
||||
immediately, Rust chooses to not compile this code at all and prevent
|
||||
misunderstandings earlier.
|
||||
@ -427,4 +427,4 @@ of strings than other programming languages do, but this will prevent you from
|
||||
having to handle errors involving non-ASCII characters later in your
|
||||
development lifecycle.
|
||||
|
||||
Let's switch to something a bit less complex: Hash Map!
|
||||
Let's switch to something a bit less complex: hash map!
|
||||
|
@ -42,7 +42,7 @@ there's no built-in macro to construct them, for example.
|
||||
|
||||
Just like vectors, hash maps store their data on the heap. This `HashMap` has
|
||||
keys of type `&str` and values of type `i32`. Like vectors, hash maps are
|
||||
homogenous: all of the keys must have the same type, and all of the values must
|
||||
homogeneous: all of the keys must have the same type, and all of the values must
|
||||
have the same type.
|
||||
|
||||
Another way of constructing a hash map is by using the `collect` method on a
|
||||
@ -68,7 +68,7 @@ want unless you specify. For the type parameters for the key and value types,
|
||||
however, we use underscores and Rust can infer the types that the hash map
|
||||
contains based on the types of the data in the vector.
|
||||
|
||||
### Hashmaps and Ownership
|
||||
### Hash Maps and Ownership
|
||||
|
||||
For types that implement the `Copy` trait, like `i32`, the values are copied
|
||||
into the hash map. For owned values like `String`, the values will be moved and
|
||||
@ -156,7 +156,7 @@ Let's look at how to do each of these!
|
||||
|
||||
#### Overwriting a Value
|
||||
|
||||
If we insert a key and a value into a hashmap, then insert that same key with a
|
||||
If we insert a key and a value into a hash map, then insert that same key with a
|
||||
different value, the value associated with that key will be replaced. Even
|
||||
though this following code calls `insert` twice, the hash map will only contain
|
||||
one key/value pair because we're inserting the value for the Blue team's key
|
||||
|
Loading…
Reference in New Issue
Block a user