mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
tutorial: Fill out bounded type test case
This commit is contained in:
parent
b95a4daa60
commit
e4a3b9ac69
@ -2507,10 +2507,15 @@ values of *an* unknown type that conforms to a given interface.
|
||||
However, consider this function:
|
||||
|
||||
~~~~
|
||||
# type circle = int; type rectangle = int;
|
||||
# iface drawable { fn draw(); }
|
||||
# impl of drawable for int { fn draw() {} }
|
||||
# fn new_circle() -> int { 1 }
|
||||
fn draw_all<T: drawable>(shapes: ~[T]) {
|
||||
for shapes.each |shape| { shape.draw(); }
|
||||
}
|
||||
# let c: circle = new_circle();
|
||||
# draw_all(~[c]);
|
||||
~~~~
|
||||
|
||||
You can call that on an array of circles, or an array of squares
|
||||
|
Loading…
Reference in New Issue
Block a user