Skip to content

Commit 979f7cd

Browse files
committed
rollup merge of #17695 : steveklabnik/various_docs
2 parents 67717b6 + 16cca6d commit 979f7cd

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/doc/guide-lifetimes.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,17 @@ copying.
305305
# Circle(Point, f64), // origin, radius
306306
# Rectangle(Point, Size) // upper-left, dimensions
307307
# }
308-
# static tau: f64 = 6.28;
309308
fn compute_area(shape: &Shape) -> f64 {
310309
match *shape {
311-
Circle(_, radius) => 0.5 * tau * radius * radius,
310+
Circle(_, radius) => std::f64::consts::PI * radius * radius,
312311
Rectangle(_, ref size) => size.w * size.h
313312
}
314313
}
315314
~~~
316315

317316
The first case matches against circles. Here, the pattern extracts the
318317
radius from the shape variant and the action uses it to compute the
319-
area of the circle. (Like any up-to-date engineer, we use the [tau
320-
circle constant][tau] and not that dreadfully outdated notion of pi).
321-
322-
[tau]: http://www.math.utah.edu/~palais/pi.html
318+
area of the circle.
323319

324320
The second match is more interesting. Here we match against a
325321
rectangle and extract its size: but rather than copy the `size`

src/doc/guide.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,12 @@ error: mismatched types: expected `int` but found `()` (expected int but found (
659659
```
660660

661661
We expected an integer, but we got `()`. `()` is pronounced 'unit', and is a
662-
special type in Rust's type system. `()` is different than `null` in other
663-
languages, because `()` is distinct from other types. For example, in C, `null`
664-
is a valid value for a variable of type `int`. In Rust, `()` is _not_ a valid
665-
value for a variable of type `int`. It's only a valid value for variables of
666-
the type `()`, which aren't very useful. Remember how we said statements don't
667-
return a value? Well, that's the purpose of unit in this case. The semicolon
668-
turns any expression into a statement by throwing away its value and returning
669-
unit instead.
662+
special type in Rust's type system. In Rust, `()` is _not_ a valid value for a
663+
variable of type `int`. It's only a valid value for variables of the type `()`,
664+
which aren't very useful. Remember how we said statements don't return a value?
665+
Well, that's the purpose of unit in this case. The semicolon turns any
666+
expression into a statement by throwing away its value and returning unit
667+
instead.
670668

671669
There's one more time in which you won't see a semicolon at the end of a line
672670
of Rust code. For that, we'll need our next concept: functions.
@@ -1680,11 +1678,11 @@ just `int`s.
16801678

16811679
Rust provides a method on these `IoResult<T>`s called `ok()`, which does the
16821680
same thing as our `match` statement, but assuming that we have a valid value.
1683-
If we don't, it will terminate our program. In this case, if we can't get
1684-
input, our program doesn't work, so we're okay with that. In most cases, we
1685-
would want to handle the error case explicitly. The result of `ok()` has a
1686-
method, `expect()`, which allows us to give an error message if this crash
1687-
happens.
1681+
We then call `expect()` on the result, which will terminate our program if we
1682+
don't have a valid value. In this case, if we can't get input, our program
1683+
doesn't work, so we're okay with that. In most cases, we would want to handle
1684+
the error case explicitly. `expect()` allows us to give an error message if
1685+
this crash happens.
16881686

16891687
We will cover the exact details of how all of this works later in the Guide.
16901688
For now, this gives you enough of a basic understanding to work with.
@@ -2030,7 +2028,7 @@ fn main() {
20302028
match cmp(input, secret_number) {
20312029
Less => println!("Too small!"),
20322030
Greater => println!("Too big!"),
2033-
Equal => { println!("You win!"); },
2031+
Equal => println!("You win!"),
20342032
}
20352033
}
20362034

0 commit comments

Comments
 (0)