@@ -2044,13 +2044,11 @@ However, consider this function:
2044
2044
# type Circle = int; type Rectangle = int;
2045
2045
# impl int: Drawable { fn draw() {} }
2046
2046
# fn new_circle() -> int { 1 }
2047
-
2048
2047
trait Drawable { fn draw(); }
2049
2048
2050
2049
fn draw_all<T: Drawable>(shapes: ~[T]) {
2051
2050
for shapes.each |shape| { shape.draw(); }
2052
2051
}
2053
-
2054
2052
# let c: Circle = new_circle();
2055
2053
# draw_all(~[c]);
2056
2054
~~~~
@@ -2062,7 +2060,7 @@ needed, a trait name can alternately be used as a type.
2062
2060
2063
2061
~~~~
2064
2062
# trait Drawable { fn draw(); }
2065
- fn draw_all(shapes: ~ [@Drawable]) {
2063
+ fn draw_all(shapes: & [@Drawable]) {
2066
2064
for shapes.each |shape| { shape.draw(); }
2067
2065
}
2068
2066
~~~~
@@ -2077,15 +2075,15 @@ to cast a value to a trait type:
2077
2075
# trait Drawable { fn draw(); }
2078
2076
# fn new_circle() -> Circle { 1 }
2079
2077
# fn new_rectangle() -> Rectangle { true }
2080
- # fn draw_all(shapes: ~[ Drawable]) {}
2078
+ # fn draw_all(shapes: &[@ Drawable]) {}
2081
2079
2082
2080
impl @Circle: Drawable { fn draw() { ... } }
2083
2081
2084
2082
impl @Rectangle: Drawable { fn draw() { ... } }
2085
2083
2086
2084
let c: @Circle = @new_circle();
2087
2085
let r: @Rectangle = @new_rectangle();
2088
- draw_all(~ [c as @Drawable, r as @Drawable]);
2086
+ draw_all(& [c as @Drawable, r as @Drawable]);
2089
2087
~~~~
2090
2088
2091
2089
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,
2130
2128
` farm::chicken ` .
2131
2129
2132
2130
~~~~
2133
- #[legacy_exports]
2134
2131
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" }
2137
2134
}
2138
2135
fn main() {
2139
2136
io::println(farm::chicken());
0 commit comments