about summary refs log tree commit diff
path: root/src/libstd/smallintmap.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-07-27 14:51:19 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-07-27 14:52:46 -0700
commit01e2471cb7bc7f84863bdb0d67cfa2af16d54f9e (patch)
treedd3e607ce180e39a3f1a6ee9bf123fda13db3dbd /src/libstd/smallintmap.rs
parentb6aadf56c8a6e603c79a8924e6a92398471de8cf (diff)
downloadrust-01e2471cb7bc7f84863bdb0d67cfa2af16d54f9e.tar.gz
rust-01e2471cb7bc7f84863bdb0d67cfa2af16d54f9e.zip
core: Trait-ify various overloaded operators
Diffstat (limited to 'src/libstd/smallintmap.rs')
-rw-r--r--src/libstd/smallintmap.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index 02948f58fc4..0325ef3ac2e 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -35,7 +35,7 @@ fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
  * Get the value for the specified key. If the key does not exist
  * in the map then returns none
  */
-fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
+pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
     if key < self.v.len() { ret self.v.get_elt(key); }
     ret none::<T>;
 }
@@ -47,7 +47,7 @@ fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
  *
  * If the key does not exist in the map
  */
-fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
+pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
     alt find(self, key) {
       none { #error("smallintmap::get(): key not present"); fail; }
       some(v) { ret v; }
@@ -114,6 +114,14 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
     }
 }
 
+impl extensions<V: copy> of ops::index<uint, V> for smallintmap<V> {
+    pure fn index(&&key: uint) -> V {
+        unchecked {
+            get(self, key)
+        }
+    }
+}
+
 /// Cast the given smallintmap to a map::map
 fn as_map<V: copy>(s: smallintmap<V>) -> map::map<uint, V> {
     s as map::map::<uint, V>