Fix two code examples in main rust tutorial.
1. The section on trait definitions of static methods should include a trait with a static method in the generated document. 2. The section on trait inheritance had a expression that appears nonsensical ("let mycircle = @mycircle") in the generated document. The text would be clearer (IMO) if we continued with the running example of CircleStruct.
This commit is contained in:
parent
fc9650b146
commit
88bec09e63
1 changed files with 10 additions and 5 deletions
|
@ -2015,7 +2015,7 @@ the method name with the trait name.
|
||||||
The compiler will use type inference to decide which implementation to call.
|
The compiler will use type inference to decide which implementation to call.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# trait Shape { static fn new(area: float) -> self; }
|
trait Shape { static fn new(area: float) -> self; }
|
||||||
# use float::consts::pi;
|
# use float::consts::pi;
|
||||||
# use float::sqrt;
|
# use float::sqrt;
|
||||||
struct Circle { radius: float }
|
struct Circle { radius: float }
|
||||||
|
@ -2211,11 +2211,16 @@ Likewise, supertrait methods may also be called on trait objects.
|
||||||
~~~ {.xfail-test}
|
~~~ {.xfail-test}
|
||||||
# trait Shape { fn area(&self) -> float; }
|
# trait Shape { fn area(&self) -> float; }
|
||||||
# trait Circle : Shape { fn radius(&self) -> float; }
|
# trait Circle : Shape { fn radius(&self) -> float; }
|
||||||
# impl int: Shape { fn area(&self) -> float { 0.0 } }
|
# use float::consts::pi;
|
||||||
# impl int: Circle { fn radius(&self) -> float { 0.0 } }
|
# use float::sqrt;
|
||||||
# let mycircle = 0;
|
# struct Point { x: float, y: float }
|
||||||
|
# struct CircleStruct { center: Point, radius: float }
|
||||||
|
# impl CircleStruct: Circle { fn radius(&self) -> float { sqrt(self.area() / pi) } }
|
||||||
|
# impl CircleStruct: Shape { fn area(&self) -> float { pi * square(self.radius) } }
|
||||||
|
|
||||||
let mycircle: Circle = @mycircle as @Circle;
|
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
|
||||||
|
|
||||||
|
let mycircle: Circle = concrete as @Circle;
|
||||||
let nonsense = mycircle.radius() * mycircle.area();
|
let nonsense = mycircle.radius() * mycircle.area();
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue