Created
March 16, 2016 19:35
-
-
Save sophiajt/b13d8ae57b827bfac13c 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 FnRegisterTest { | |
fn register(self, engine: &mut Engine, name: &str); | |
} | |
impl<A: Any+Clone, B: Any+Clone, T: Fn(A)->B> FnRegisterTest for T { | |
fn register(self, engine: &mut Engine, name: &str) { | |
engine.x += 1; | |
} | |
} | |
fn id(x: i32) -> i32 { | |
x | |
} | |
fn main() { | |
let mut engine = Engine { x: 0 }; | |
id.register(&mut engine, "foo"); | |
println!("Engine: {:?}", engine); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment