@@ -499,8 +499,8 @@ types.
499
499
> items.
500
500
501
501
~~~~
502
- # use std::float;
503
- # use std::num::atan;
502
+ use std::float;
503
+ use std::num::atan;
504
504
fn angle(vector: (float, float)) -> float {
505
505
let pi = float::consts::pi;
506
506
match vector {
@@ -555,7 +555,7 @@ while cake_amount > 0 {
555
555
` loop ` denotes an infinite loop, and is the preferred way of writing ` while true ` :
556
556
557
557
~~~~
558
- # use std::int;
558
+ use std::int;
559
559
let mut x = 5;
560
560
loop {
561
561
x += x - 3;
@@ -701,7 +701,7 @@ get at their contents. All variant constructors can be used as
701
701
patterns, as in this definition of ` area ` :
702
702
703
703
~~~~
704
- # use std::float;
704
+ use std::float;
705
705
# struct Point {x: float, y: float}
706
706
# enum Shape { Circle(Point, float), Rectangle(Point, Point) }
707
707
fn area(sh: Shape) -> float {
@@ -733,7 +733,7 @@ fn point_from_direction(dir: Direction) -> Point {
733
733
Enum variants may also be structs. For example:
734
734
735
735
~~~~
736
- # use std::float;
736
+ use std::float;
737
737
# struct Point { x: float, y: float }
738
738
# fn square(x: float) -> float { x * x }
739
739
enum Shape {
@@ -1599,7 +1599,8 @@ lists back to back. Since that is so unsightly, empty argument lists
1599
1599
may be omitted from ` do ` expressions.
1600
1600
1601
1601
~~~~
1602
- # use std::task::spawn;
1602
+ use std::task::spawn;
1603
+
1603
1604
do spawn {
1604
1605
debug!("Kablam!");
1605
1606
}
@@ -1728,7 +1729,7 @@ impl Circle {
1728
1729
To call such a method, just prefix it with the type name and a double colon:
1729
1730
1730
1731
~~~~
1731
- # use std::float::consts::pi;
1732
+ use std::float::consts::pi;
1732
1733
struct Circle { radius: float }
1733
1734
impl Circle {
1734
1735
fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
@@ -1774,7 +1775,7 @@ illegal to copy and pass by value.
1774
1775
Generic ` type ` , ` struct ` , and ` enum ` declarations follow the same pattern:
1775
1776
1776
1777
~~~~
1777
- # use std::hashmap::HashMap;
1778
+ use std::hashmap::HashMap;
1778
1779
type Set<T> = HashMap<T, ()>;
1779
1780
1780
1781
struct Stack<T> {
@@ -2000,7 +2001,7 @@ name and a double colon. The compiler uses type inference to decide which
2000
2001
implementation to use.
2001
2002
2002
2003
~~~~
2003
- # use std::float::consts::pi;
2004
+ use std::float::consts::pi;
2004
2005
trait Shape { fn new(area: float) -> Self; }
2005
2006
struct Circle { radius: float }
2006
2007
struct Square { length: float }
@@ -2156,7 +2157,7 @@ trait Circle : Shape { fn radius(&self) -> float; }
2156
2157
Now, we can implement ` Circle ` on a type only if we also implement ` Shape ` .
2157
2158
2158
2159
~~~~
2159
- # use std::float::consts::pi;
2160
+ use std::float::consts::pi;
2160
2161
# trait Shape { fn area(&self) -> float; }
2161
2162
# trait Circle : Shape { fn radius(&self) -> float; }
2162
2163
# struct Point { x: float, y: float }
@@ -2191,7 +2192,7 @@ fn radius_times_area<T: Circle>(c: T) -> float {
2191
2192
Likewise, supertrait methods may also be called on trait objects.
2192
2193
2193
2194
~~~ {.xfail-test}
2194
- # use std::float::consts::pi;
2195
+ use std::float::consts::pi;
2195
2196
# trait Shape { fn area(&self) -> float; }
2196
2197
# trait Circle : Shape { fn radius(&self) -> float; }
2197
2198
# struct Point { x: float, y: float }
0 commit comments