I forgot the changes to the docs as well
Apparently yesterday wasn't my day, and I forgot to add the changes to all the tests apparently, and in the end forgot the docs extra much. Please documentation, forgive me, I really do love you, I hope you forgive me. Next time we'll meet tutorial, I promise to bring cookies and tea. I really want to be best-friends-forever with you, <3. XOXO
This commit is contained in:
parent
2ed1cfc912
commit
20a2fbd055
|
@ -802,11 +802,11 @@ Use declarations support a number of convenient shortcuts:
|
|||
An example of `use` declarations:
|
||||
|
||||
~~~~
|
||||
use std::float::sin;
|
||||
use std::num::sin;
|
||||
use std::option::{Some, None};
|
||||
|
||||
fn main() {
|
||||
// Equivalent to 'info!(std::float::sin(1.0));'
|
||||
// Equivalent to 'info!(std::num::sin(1.0));'
|
||||
info!(sin(1.0));
|
||||
|
||||
// Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);'
|
||||
|
|
|
@ -503,12 +503,13 @@ types.
|
|||
|
||||
~~~~
|
||||
# use std::float;
|
||||
# use std::num::atan;
|
||||
fn angle(vector: (float, float)) -> float {
|
||||
let pi = float::consts::pi;
|
||||
match vector {
|
||||
(0f, y) if y < 0f => 1.5 * pi,
|
||||
(0f, y) => 0.5 * pi,
|
||||
(x, y) => float::atan(y / x)
|
||||
(x, y) => atan(y / x)
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
@ -1728,10 +1729,9 @@ To call such a method, just prefix it with the type name and a double colon:
|
|||
|
||||
~~~~
|
||||
# use std::float::consts::pi;
|
||||
# use std::float::sqrt;
|
||||
struct Circle { radius: float }
|
||||
impl Circle {
|
||||
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
||||
fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
|
||||
}
|
||||
let c = Circle::new(42.5);
|
||||
~~~~
|
||||
|
@ -1997,16 +1997,15 @@ implementation to use.
|
|||
|
||||
~~~~
|
||||
# use std::float::consts::pi;
|
||||
# use std::float::sqrt;
|
||||
trait Shape { fn new(area: float) -> Self; }
|
||||
struct Circle { radius: float }
|
||||
struct Square { length: float }
|
||||
|
||||
impl Shape for Circle {
|
||||
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
||||
fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } }
|
||||
}
|
||||
impl Shape for Square {
|
||||
fn new(area: float) -> Square { Square { length: sqrt(area) } }
|
||||
fn new(area: float) -> Square { Square { length: (area).sqrt() } }
|
||||
}
|
||||
|
||||
let area = 42.5;
|
||||
|
@ -2154,14 +2153,13 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
|
|||
|
||||
~~~~
|
||||
# use std::float::consts::pi;
|
||||
# use std::float::sqrt;
|
||||
# trait Shape { fn area(&self) -> float; }
|
||||
# trait Circle : Shape { fn radius(&self) -> float; }
|
||||
# struct Point { x: float, y: float }
|
||||
# fn square(x: float) -> float { x * x }
|
||||
struct CircleStruct { center: Point, radius: float }
|
||||
impl Circle for CircleStruct {
|
||||
fn radius(&self) -> float { sqrt(self.area() / pi) }
|
||||
fn radius(&self) -> float { (self.area() / pi).sqrt() }
|
||||
}
|
||||
impl Shape for CircleStruct {
|
||||
fn area(&self) -> float { pi * square(self.radius) }
|
||||
|
@ -2190,12 +2188,11 @@ Likewise, supertrait methods may also be called on trait objects.
|
|||
|
||||
~~~ {.xfail-test}
|
||||
# use std::float::consts::pi;
|
||||
# use std::float::sqrt;
|
||||
# trait Shape { fn area(&self) -> float; }
|
||||
# trait Circle : Shape { fn radius(&self) -> float; }
|
||||
# struct Point { x: float, y: float }
|
||||
# struct CircleStruct { center: Point, radius: float }
|
||||
# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
|
||||
# impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt() } }
|
||||
# impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } }
|
||||
|
||||
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
|
||||
|
|
Loading…
Reference in New Issue