Skip to content

Instantly share code, notes, and snippets.

@sophiajt
Created March 16, 2016 19:35
Show Gist options
  • Save sophiajt/b13d8ae57b827bfac13c to your computer and use it in GitHub Desktop.
Save sophiajt/b13d8ae57b827bfac13c to your computer and use it in GitHub Desktop.
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