Skip to content

Instantly share code, notes, and snippets.

@MaikKlein
Created June 22, 2013 14:31
Show Gist options
  • Save MaikKlein/5841087 to your computer and use it in GitHub Desktop.
Save MaikKlein/5841087 to your computer and use it in GitHub Desktop.
trait Visior<T>{
fn visit(&self, t: T);
}
struct PrintVisitor;
impl PrintVisitor {
fn print(&self, s: ~str){
println(s);
}
}
impl Visior<~str> for PrintVisitor {
fn visit(&self, s: ~str){
print(s);
}
}
struct SomeObject;
impl SomeObject {
fn do_sth(&self, v: &Visior<~str>, s: ~str){
v.visit(s);
}
}
fn main(){
let v = PrintVisitor;
let o = SomeObject;
o.do_sth(v, ~"Hello");
}
/home/maik/hello.rs:30:9: 30:10 error: mismatched types: expected `&Visior<~str>` but found `PrintVisitor` (expected trait Visior but found struct PrintVisitor)
/home/maik/hello.rs:30 o.do_sth(v, ~"Hello");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment