Last active
March 16, 2016 19:48
-
-
Save sophiajt/97bd4bba5ed273254944 to your computer and use it in GitHub Desktop.
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
use std::any::Any; | |
#[derive(Debug)] | |
struct Engine { | |
x: i32 | |
} | |
trait FnRegister1V { | |
fn register<T: Fn(U)->V, U, V>(&mut self, name: &str, f: T); | |
} | |
impl FnRegister1V for Engine { | |
fn register<T: Fn(U)->V, U, V>(&mut self, name: &str, f: T) { | |
self.x += 2; | |
} | |
} | |
trait FnRegister2V { | |
fn register<T: Fn(U, V)->W, U, V, W>(&mut self, name: &str, f: T); | |
} | |
impl FnRegister2V for Engine { | |
fn register<T: Fn(U, V)->W, U, V, W>(&mut self, name: &str, f: T) { | |
self.x += 2; | |
} | |
} | |
fn id(x: i32) -> i32 { | |
x | |
} | |
fn main() { | |
let mut engine = Engine { x: 0 }; | |
engine.register("foo", id); | |
println!("Engine: {:?}", engine); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment