Skip to content

Commit 035cfcb

Browse files
committed
docs: Clean up trait and module examples
1 parent f96a2a2 commit 035cfcb

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

doc/tutorial.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,13 +2044,11 @@ However, consider this function:
20442044
# type Circle = int; type Rectangle = int;
20452045
# impl int: Drawable { fn draw() {} }
20462046
# fn new_circle() -> int { 1 }
2047-
20482047
trait Drawable { fn draw(); }
20492048
20502049
fn draw_all<T: Drawable>(shapes: ~[T]) {
20512050
for shapes.each |shape| { shape.draw(); }
20522051
}
2053-
20542052
# let c: Circle = new_circle();
20552053
# draw_all(~[c]);
20562054
~~~~
@@ -2062,7 +2060,7 @@ needed, a trait name can alternately be used as a type.
20622060

20632061
~~~~
20642062
# trait Drawable { fn draw(); }
2065-
fn draw_all(shapes: ~[@Drawable]) {
2063+
fn draw_all(shapes: &[@Drawable]) {
20662064
for shapes.each |shape| { shape.draw(); }
20672065
}
20682066
~~~~
@@ -2077,15 +2075,15 @@ to cast a value to a trait type:
20772075
# trait Drawable { fn draw(); }
20782076
# fn new_circle() -> Circle { 1 }
20792077
# fn new_rectangle() -> Rectangle { true }
2080-
# fn draw_all(shapes: ~[Drawable]) {}
2078+
# fn draw_all(shapes: &[@Drawable]) {}
20812079
20822080
impl @Circle: Drawable { fn draw() { ... } }
20832081
20842082
impl @Rectangle: Drawable { fn draw() { ... } }
20852083
20862084
let c: @Circle = @new_circle();
20872085
let r: @Rectangle = @new_rectangle();
2088-
draw_all(~[c as @Drawable, r as @Drawable]);
2086+
draw_all(&[c as @Drawable, r as @Drawable]);
20892087
~~~~
20902088

20912089
Note that, like strings and vectors, trait types have dynamic size
@@ -2130,10 +2128,9 @@ explicitly import it, you must refer to it by its long name,
21302128
`farm::chicken`.
21312129

21322130
~~~~
2133-
#[legacy_exports]
21342131
mod farm {
2135-
fn chicken() -> ~str { ~"cluck cluck" }
2136-
fn cow() -> ~str { ~"mooo" }
2132+
pub fn chicken() -> ~str { ~"cluck cluck" }
2133+
pub fn cow() -> ~str { ~"mooo" }
21372134
}
21382135
fn main() {
21392136
io::println(farm::chicken());

0 commit comments

Comments
 (0)