Created
January 25, 2013 21:11
-
-
Save Lazin/4637894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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