Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2017 14:25
Show Gist options
  • Save anonymous/5ea679e2da700964afb2a08252cf6c6d to your computer and use it in GitHub Desktop.
Save anonymous/5ea679e2da700964afb2a08252cf6c6d to your computer and use it in GitHub Desktop.
Rust code shared from the playground
#![feature(proc_macro, unboxed_closures)]
use std::any::{Any};
fn main() {
let any_box_box = Box::new(ff()) as Box<Any + 'static>;
let g = any_box_box.downcast_ref::<Box<Fn<(u32,), Output = u32>>>().expect("Cast D:");
let gg = g.as_ref();
println!("{}", gg(2u32));
}
fn ff() -> Box<Fn<(u32,), Output = u32>> {
Box::new(|x: u32| x * 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment