Created
March 23, 2016 10:10
-
-
Save anonymous/529349a3a8315c68869a 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<A, C: Fn<A>>(_: &C) -> extern "rust-call" fn(&(), A) -> C::Output { | |
let fn_ptr: extern "rust-call" fn(&(), A) -> C::Output = unsafe { | |
std::mem::transmute(<C as std::ops::Fn<A>>::call as usize) | |
}; | |
fn_ptr | |
} | |
fn main() { | |
let closure = |x| { println!("hi {}", x) }; | |
let ptr = get_fn_ptr(&closure); | |
ptr(&(), ("bstrie",)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment