Created
May 18, 2014 06:27
-
-
Save huonw/7e48f0bc2bbcc9ad3443 to your computer and use it in GitHub Desktop.
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
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