mirror of
https://github.com/rust-lang/book.git
synced 2026-09-15 10:10:42 -04:00
Address steve's comments
This commit is contained in:
@@ -49,17 +49,17 @@ Note that we added a type annotation here. Because 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 implemented using generics;
|
||||
we’ll cover how to use generics with your own types in Chapter 10. For now,
|
||||
know that the `Vec` type provided by the standard library can hold any type,
|
||||
and when a specific `Vec` holds a specific type, the type is specified within
|
||||
angle brackets. In Listing 8-1, we’ve told Rust that the `Vec` in `v` will hold
|
||||
elements of the `i32` type.
|
||||
know that the `Vec<T>` type provided by the standard library can hold any type,
|
||||
and when a specific vector holds a specific type, the type is specified within
|
||||
angle brackets. In Listing 8-1, we’ve told Rust that the `Vec<T>` in `v` will
|
||||
hold elements of the `i32` type.
|
||||
|
||||
In more realistic code, Rust can often infer the type of value we want to store
|
||||
once we insert values, so you rarely need to do this type annotation. It’s more
|
||||
common to create a `Vec` that has initial values, and Rust provides the `vec!`
|
||||
macro for convenience. The macro will create a new `Vec` that holds the values
|
||||
we give it. Listing 8-2 creates a new `Vec<i32>` that holds the values `1`,
|
||||
`2`, and `3`:
|
||||
common to create a `Vec<T>` that has initial values, and Rust provides the
|
||||
`vec!` macro for convenience. The macro will create a new vector that holds the
|
||||
values we give it. Listing 8-2 creates a new `Vec<i32>` that holds the values
|
||||
`1`, `2`, and `3`:
|
||||
|
||||
```rust
|
||||
let v = vec![1, 2, 3];
|
||||
@@ -389,7 +389,7 @@ string literal
|
||||
Because strings are used for so many things, we can use many different generic
|
||||
APIs for strings, providing us with a lot of options. Some of them can seem
|
||||
redundant, but they all have their place! In this case, `String::from` and
|
||||
`.to_string` do the same thing, so which you choose is a matter of style.
|
||||
`to_string` do the same thing, so which you choose is a matter of style.
|
||||
|
||||
Remember that strings are UTF-8 encoded, so we can include any properly encoded
|
||||
data in them, as shown in Listing 8-12:
|
||||
@@ -761,12 +761,12 @@ a team’s name and the values are each team’s score. Given a team name, you c
|
||||
retrieve its score.
|
||||
|
||||
We’ll go over the basic API of hash maps in this section, but many more goodies
|
||||
are hiding in the functions defined on `HashMap` by the standard library. As
|
||||
always, check the standard library documentation for more information.
|
||||
are hiding in the functions defined on `HashMap<K, V>` by the standard library.
|
||||
As always, check the standard library documentation for more information.
|
||||
|
||||
### Creating a New Hash Map
|
||||
|
||||
We can create an empty `HashMap` with `new` and add elements with `insert`. In
|
||||
We can create an empty hash map with `new` and add elements with `insert`. In
|
||||
Listing 8-18, we’re keeping track of the scores of two teams whose names are
|
||||
Blue and Yellow. The Blue team will start with 10 points, and the Yellow team
|
||||
starts with 50:
|
||||
|
||||
Binary file not shown.
@@ -23,17 +23,17 @@ Note that we added a type annotation here. Because 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 implemented using generics;
|
||||
we’ll cover how to use generics with your own types in Chapter 10. For now,
|
||||
know that the `Vec` type provided by the standard library can hold any type,
|
||||
and when a specific `Vec` holds a specific type, the type is specified within
|
||||
angle brackets. In Listing 8-1, we’ve told Rust that the `Vec` in `v` will hold
|
||||
elements of the `i32` type.
|
||||
know that the `Vec<T>` type provided by the standard library can hold any type,
|
||||
and when a specific vector holds a specific type, the type is specified within
|
||||
angle brackets. In Listing 8-1, we’ve told Rust that the `Vec<T>` in `v` will
|
||||
hold elements of the `i32` type.
|
||||
|
||||
In more realistic code, Rust can often infer the type of value we want to store
|
||||
once we insert values, so you rarely need to do this type annotation. It’s more
|
||||
common to create a `Vec` that has initial values, and Rust provides the `vec!`
|
||||
macro for convenience. The macro will create a new `Vec` that holds the values
|
||||
we give it. Listing 8-2 creates a new `Vec<i32>` that holds the values `1`,
|
||||
`2`, and `3`:
|
||||
common to create a `Vec<T>` that has initial values, and Rust provides the
|
||||
`vec!` macro for convenience. The macro will create a new vector that holds the
|
||||
values we give it. Listing 8-2 creates a new `Vec<i32>` that holds the values
|
||||
`1`, `2`, and `3`:
|
||||
|
||||
```rust
|
||||
let v = vec![1, 2, 3];
|
||||
|
||||
@@ -86,7 +86,7 @@ a `String` from a string literal</span>
|
||||
Because strings are used for so many things, we can use many different generic
|
||||
APIs for strings, providing us with a lot of options. Some of them can seem
|
||||
redundant, but they all have their place! In this case, `String::from` and
|
||||
`.to_string` do the same thing, so which you choose is a matter of style.
|
||||
`to_string` do the same thing, so which you choose is a matter of style.
|
||||
|
||||
Remember that strings are UTF-8 encoded, so we can include any properly encoded
|
||||
data in them, as shown in Listing 8-12:
|
||||
|
||||
@@ -14,12 +14,12 @@ a team’s name and the values are each team’s score. Given a team name, you c
|
||||
retrieve its score.
|
||||
|
||||
We’ll go over the basic API of hash maps in this section, but many more goodies
|
||||
are hiding in the functions defined on `HashMap` by the standard library. As
|
||||
always, check the standard library documentation for more information.
|
||||
are hiding in the functions defined on `HashMap<K, V>` by the standard library.
|
||||
As always, check the standard library documentation for more information.
|
||||
|
||||
### Creating a New Hash Map
|
||||
|
||||
We can create an empty `HashMap` with `new` and add elements with `insert`. In
|
||||
We can create an empty hash map with `new` and add elements with `insert`. In
|
||||
Listing 8-18, we’re keeping track of the scores of two teams whose names are
|
||||
Blue and Yellow. The Blue team will start with 10 points, and the Yellow team
|
||||
starts with 50:
|
||||
|
||||
Reference in New Issue
Block a user