Auto merge of #25421 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #25404, #25405, #25407, #25408, #25410, #25412, #25413, #25414, #25418, #25420 - Failed merges:
This commit is contained in:
commit
daabc8a0c7
@ -6,7 +6,7 @@ and more cores, yet many programmers aren't prepared to fully utilize them.
|
||||
|
||||
Rust's memory safety features also apply to its concurrency story too. Even
|
||||
concurrent Rust programs must be memory safe, having no data races. Rust's type
|
||||
system is up to the thread, and gives you powerful ways to reason about
|
||||
system is up to the task, and gives you powerful ways to reason about
|
||||
concurrent code at compile time.
|
||||
|
||||
Before we talk about the concurrency features that come with Rust, it's important
|
||||
|
@ -73,6 +73,9 @@ a name is all we need. We choose the [`String`][string] type for the name,
|
||||
rather than `&str`. Generally speaking, working with a type which owns its
|
||||
data is easier than working with one that uses references.
|
||||
|
||||
[struct]: structs.html
|
||||
[string]: strings.html
|
||||
|
||||
Let’s continue:
|
||||
|
||||
```rust
|
||||
|
@ -55,9 +55,6 @@ fn process_color_change(msg: Message) {
|
||||
}
|
||||
```
|
||||
|
||||
Both variants are named `Digit`, but since they’re scoped to the `enum` name
|
||||
there's no ambiguity.
|
||||
|
||||
Not supporting these operations may seem rather limiting, but it’s a limitation
|
||||
which we can overcome. There are two ways: by implementing equality ourselves,
|
||||
or by pattern matching variants with [`match`][match] expressions, which you’ll
|
||||
@ -66,3 +63,4 @@ equality yet, but we’ll find out in the [`traits`][traits] section.
|
||||
|
||||
[match]: match.html
|
||||
[if-let]: if-let.html
|
||||
[traits]: traits.html
|
||||
|
@ -213,12 +213,12 @@ The next part will use this handle to get input from the user:
|
||||
```
|
||||
|
||||
Here, we call the [`read_line()`][read_line] method on our handle.
|
||||
[Method][method]s are like associated functions, but are only available on a
|
||||
[Methods][method] are like associated functions, but are only available on a
|
||||
particular instance of a type, rather than the type itself. We’re also passing
|
||||
one argument to `read_line()`: `&mut guess`.
|
||||
|
||||
[read_line]: ../std/io/struct.Stdin.html#method.read_line
|
||||
[method]: methods.html
|
||||
[method]: method-syntax.html
|
||||
|
||||
Remember how we bound `guess` above? We said it was mutable. However,
|
||||
`read_line` doesn’t take a `String` as an argument: it takes a `&mut String`.
|
||||
|
@ -97,4 +97,4 @@ Unlike the previous uses of `match`, you can’t use the normal `if`
|
||||
statement to do this. You can use the [`if let`][if-let] statement,
|
||||
which can be seen as an abbreviated form of `match`.
|
||||
|
||||
[if-let][if-let.html]
|
||||
[if-let]: if-let.html
|
||||
|
@ -35,7 +35,7 @@ let y = &mut x;
|
||||
|
||||
`y` is an immutable binding to a mutable reference, which means that you can’t
|
||||
bind `y` to something else (`y = &mut z`), but you can mutate the thing that’s
|
||||
bound to `y`. (`*y = 5`) A subtle distinction.
|
||||
bound to `y` (`*y = 5`). A subtle distinction.
|
||||
|
||||
Of course, if you need both:
|
||||
|
||||
|
@ -66,7 +66,7 @@ match x {
|
||||
}
|
||||
```
|
||||
|
||||
This prints `something else`
|
||||
This prints `something else`.
|
||||
|
||||
# Bindings
|
||||
|
||||
@ -152,7 +152,7 @@ match x {
|
||||
}
|
||||
```
|
||||
|
||||
This prints `Got an int!`
|
||||
This prints `Got an int!`.
|
||||
|
||||
# ref and ref mut
|
||||
|
||||
|
@ -196,3 +196,5 @@ useful. For instance, a library may ask you to create a structure that
|
||||
implements a certain [trait][trait] to handle events. If you don’t have
|
||||
any data you need to store in the structure, you can just create a
|
||||
unit-like struct.
|
||||
|
||||
[trait]: traits.html
|
||||
|
@ -430,7 +430,7 @@ Next, `foo()` calls `bar()` with `x` and `z`:
|
||||
| 2<sup>30</sup> | | 20 |
|
||||
| (2<sup>30</sup>) - 1 | | 5 |
|
||||
| ... | ... | ... |
|
||||
| 10 | e | 4 |
|
||||
| 10 | e | 9 |
|
||||
| 9 | d | (2<sup>30</sup>) - 1 |
|
||||
| 8 | c | 5 |
|
||||
| 7 | b | 4 |
|
||||
@ -455,7 +455,7 @@ At the end of `bar()`, it calls `baz()`:
|
||||
| ... | ... | ... |
|
||||
| 12 | g | 100 |
|
||||
| 11 | f | 4 |
|
||||
| 10 | e | 4 |
|
||||
| 10 | e | 9 |
|
||||
| 9 | d | (2<sup>30</sup>) - 1 |
|
||||
| 8 | c | 5 |
|
||||
| 7 | b | 4 |
|
||||
@ -477,7 +477,7 @@ After `baz()` is over, we get rid of `f` and `g`:
|
||||
| 2<sup>30</sup> | | 20 |
|
||||
| (2<sup>30</sup>) - 1 | | 5 |
|
||||
| ... | ... | ... |
|
||||
| 10 | e | 4 |
|
||||
| 10 | e | 9 |
|
||||
| 9 | d | (2<sup>30</sup>) - 1 |
|
||||
| 8 | c | 5 |
|
||||
| 7 | b | 4 |
|
||||
|
@ -3,7 +3,7 @@
|
||||
Rust also has a `while` loop. It looks like this:
|
||||
|
||||
```{rust}
|
||||
let mut x = 5; // mut x: u32
|
||||
let mut x = 5; // mut x: i32
|
||||
let mut done = false; // mut done: bool
|
||||
|
||||
while !done {
|
||||
|
@ -396,6 +396,7 @@ macro_rules! utf8_acc_cont_byte {
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Borrow<str> for String {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &str { &self[..] }
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
//! [`result`](result/index.html) modules define optional and
|
||||
//! error-handling types, `Option` and `Result`. The
|
||||
//! [`iter`](iter/index.html) module defines Rust's iterator trait,
|
||||
//! [`Iterater`](iter/trait.Iterator.html), which works with the `for`
|
||||
//! [`Iterator`](iter/trait.Iterator.html), which works with the `for`
|
||||
//! loop to access collections.
|
||||
//!
|
||||
//! The common container type, `Vec`, a growable vector backed by an array,
|
||||
|
Loading…
Reference in New Issue
Block a user