Created
July 4, 2013 20:34
-
-
Save jmgrosen/5930078 to your computer and use it in GitHub Desktop.
This file contains 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::vec; | |
struct IndexableThing; | |
impl Index<uint, ~str> for IndexableThing { | |
fn index(&self, rhs: &uint) -> ~str { | |
(*rhs).to_str() | |
} | |
} | |
impl Index<uint, ~[uint]> for IndexableThing { | |
fn index(&self, rhs: &uint) -> ~[uint] { | |
vec::from_fn(*rhs, |i| i) | |
} | |
} | |
fn main() { | |
let thing = IndexableThing; | |
let thing_str: ~str = thing[5]; | |
println(thing_str); | |
let thing_vec: ~[uint] = thing[5]; | |
println(fmt!("%?", thing_vec)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment