Skip to content

Instantly share code, notes, and snippets.

@huonw
Created May 18, 2014 06:27
Show Gist options
  • Save huonw/7e48f0bc2bbcc9ad3443 to your computer and use it in GitHub Desktop.
Save huonw/7e48f0bc2bbcc9ad3443 to your computer and use it in GitHub Desktop.
use std::any::{Any,AnyRefExt};
trait Object {
fn as_any<'a>(&'a self) -> &'a Any {
self as &Any
}
}
impl Object for uint {}
impl Object for &'static str {}
fn main() {
let n: &Object = &3u;
let m: &uint = n.as_any().as_ref().unwrap();
println!("{}", m);
let s: &Object = &("foo");
let r: &&'static str = s.as_any().as_ref().unwrap();
println!("{}", r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment