Created
March 16, 2016 20:31
-
-
Save sophiajt/9682e655a3a3e2f470dc 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 FnRegister<RetVal, Args> { | |
fn register<T: Fn(Args)->RetVal>(&mut self, name: &str, f: T); | |
} | |
impl FnRegister<i32, (i32, i32)> for Engine { | |
fn register<T: Fn(i32, i32)->i32>(&mut self, name: &str, f: T) { | |
self.x += 2; | |
} | |
} | |
fn add(x:i32, y: i32) -> i32 { | |
x + 10 | |
} | |
fn main() { | |
let mut engine = Engine { x: 0 }; | |
engine.register("bar", add); | |
println!("Engine: {:?}", engine); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment