Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / playground.rs
Created July 25, 2017 14:25
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));
}
anonymous
anonymous / playground.rs
Created July 25, 2017 12:33
Rust code shared from the playground
fn main() {
let s = "def".to_string();
foo(|_| unsafe{as_mut_static(&s)});
}
fn foo<F: Fn(&u32) -> &mut String>(f: F) {
let x = 4;
let s = f(&x);
s.push_str("aaa ");
s.push_str(&f(&x));