Created
April 21, 2013 04:13
-
-
Save mstewartgallus/5428464 to your computer and use it in GitHub Desktop.
Buggy OneShot Function Implementation
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
// Rust lacks closures that can only be used once so they are emulated here. | |
priv trait OneShot <T> { | |
fn run (~self) -> T; | |
} | |
priv struct AnonymousOneShot <S, T> (S, ~fn (S) -> T); | |
impl <S, T> OneShot <T> for AnonymousOneShot <S, T> { | |
fn run (~self) -> T { | |
let ~AnonymousOneShot (x, f) = self; | |
f (x) | |
} | |
} | |
priv fn one_shot <S, T> (x : S, f : ~fn (S) -> T) -> ~OneShot <T> { | |
~AnonymousOneShot::<S, T> (x, f) as ~OneShot <T> | |
} | |
fn main () { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment