Created
July 25, 2017 14:25
-
-
Save anonymous/5ea679e2da700964afb2a08252cf6c6d to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
#![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