Created
April 1, 2013 21:52
-
-
Save drbawb/5288061 to your computer and use it in GitHub Desktop.
Iterating over Traits causes segfault on Linux! (rust 0.6)
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
extern mod std; | |
struct Dog { | |
name : ~str | |
} | |
trait Barks { | |
fn bark(&self) -> ~str; | |
} | |
impl Barks for Dog { | |
fn bark(&self) -> ~str { | |
let mut out = ~"woof! (I'm "; | |
out = str::append(out, self.name); | |
out = str::append(out, ~")"); | |
return out; | |
} | |
} | |
fn main() { | |
let snoopy = ~Dog{name: ~"snoopy"}; | |
let bubbles = ~Dog{name: ~"bubbles"}; | |
let barker = [snoopy as ~Barks, bubbles as ~Barks]; | |
for barker.each |pup| { | |
println(fmt!("%s", pup.bark())); | |
} | |
} | |
// Expected Output: "woof! (I'm snoopy)" | |
// > "woof! (I'm bubbles)" | |
// Actual Ouptut: | |
// "woof! (I'm snoopy)" | |
// SEGMENTATION FAULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment