Skip to content

Commit

Permalink
🔥 τ
Browse files Browse the repository at this point in the history
Fixes #17674
  • Loading branch information
steveklabnik committed Oct 1, 2014
1 parent 49fcb27 commit fc818ff
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/doc/guide-lifetimes.md
Expand Up @@ -305,21 +305,17 @@ copying.
# Circle(Point, f64), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions
# }
# static tau: f64 = 6.28;
fn compute_area(shape: &Shape) -> f64 {
match *shape {
Circle(_, radius) => 0.5 * tau * radius * radius,
Circle(_, radius) => 2.0 * std::f64::consts::PI * radius * radius,
Rectangle(_, ref size) => size.w * size.h
}
}
~~~

The first case matches against circles. Here, the pattern extracts the
radius from the shape variant and the action uses it to compute the
area of the circle. (Like any up-to-date engineer, we use the [tau
circle constant][tau] and not that dreadfully outdated notion of pi).

[tau]: http://www.math.utah.edu/~palais/pi.html
area of the circle.

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

0 comments on commit fc818ff

Please sign in to comment.