Created
March 23, 2016 09:56
-
-
Save anonymous/a1bc5830927b9f1b98ca to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
#![feature(unboxed_closures, fn_traits)] | |
fn get_fn_ptr<C: Fn() -> ()>(_: &C) -> extern "rust-call" fn(&(), ()) -> () { | |
let fn_ptr: extern "rust-call" fn(&(), ()) -> () = unsafe { std::mem::transmute(<C as std::ops::Fn<()>>::call as usize) }; | |
fn_ptr | |
} | |
fn main() { | |
let closure = ||{ println!("hi") }; | |
let ptr = get_fn_ptr(&closure); | |
ptr(&(), ()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment