public
Created

  • Download Gist
gistfile1.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
trait Drawable { fn draw(&self); }
trait Printable { fn print(&self); }
 
impl Circle: Drawable { fn draw(&self) { ... } }
impl Circle: Printable { fn print(&self) { ... } }
// both traits - Printable and Drawable is
// implemented for `Circle`
 
fn draw_all(shapes: &[@(Drawable+Printable)]) { // invalid syntax in Rust
// suppose we need to accept array of object that both
// printable and drowable, for example,
// to print something to
// log if anything goes wrong
for shapes.each |shape| { shape.draw(); }
}
 
let x: @Circle = @new_circle();
 
draw_all([x as (Drawable + Printable)]); // invalid syntx
// also, loocks very wired, by this is
// what i'm looking for

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.