Skip to content

Instantly share code, notes, and snippets.

@Lazin
Created January 25, 2013 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lazin/4637894 to your computer and use it in GitHub Desktop.
Save Lazin/4637894 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment