Skip to content

Instantly share code, notes, and snippets.

@drbawb
Created April 1, 2013 21:52
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 drbawb/5288061 to your computer and use it in GitHub Desktop.
Save drbawb/5288061 to your computer and use it in GitHub Desktop.
Iterating over Traits causes segfault on Linux! (rust 0.6)
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