Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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