Created
January 29, 2014 19:51
-
-
Save flaper87/8695610 to your computer and use it in GitHub Desktop.
This file contains hidden or 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::io; | |
fn echo<T>(x:T) { io::println(format!("{}", x)); } | |
pub trait OpInt<'a> { fn call(&'a self, int, int) -> int; } | |
impl<'a> OpInt<'a> for &'a |int, int| -> int { | |
fn call(&self, a:int, b:int) -> int { | |
echo("I dont wanna die!"); | |
(*self)(a, b) | |
} | |
} | |
fn squarei<'a>(x:int, op:&'a OpInt) -> int { op.call(x, x) } | |
fn muli(x:int, y:int) -> int { | |
echo("You will never get here."); | |
x * y | |
} | |
fn main() { | |
echo("Entered main"); | |
let f = |x,y|muli(x,y); | |
{ | |
let g = &f; | |
let h = g as &OpInt; | |
let r = squarei(3, h); echo(r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment