Skip to content

Instantly share code, notes, and snippets.

@cocuh
Created May 14, 2016 14:02
Show Gist options
  • Save cocuh/77ec15f1ab58b06d6db5870ba4cfd8d0 to your computer and use it in GitHub Desktop.
Save cocuh/77ec15f1ab58b06d6db5870ba4cfd8d0 to your computer and use it in GitHub Desktop.
trait Behaviour {
fn run(&self);
}
struct YoujoBehaviour{}
impl Behaviour for YoujoBehaviour{
fn run(&self){println!("はわわ");}
}
struct Caller<'a> {
behaviour: Box<Behaviour+'a>,
}
impl<'a> Caller<'a> {
fn run(&self) {
self.behaviour.run();
}
}
fn main(){
let c = Caller{behaviour: Box::new(YoujoBehaviour{})};
c.run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment