diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/map.rs | 7 | ||||
| -rw-r--r-- | src/libstd/smallintmap.rs | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 00d4a5e6b31..21fe5163bb5 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -45,6 +45,9 @@ iface map<K, V: copy> { "] fn get(K) -> V; + #[doc = "Like get, but as an operator."] + fn [](K) -> V; + #[doc = " Get the value for the specified key. If the key does not exist in the map then returns none. @@ -232,6 +235,10 @@ mod chained { option::get(self.find(k)) } + fn [](k: K) -> V { + option::get(self.find(k)) + } + fn remove(k: K) -> option<V> { alt self.search_tbl(k, self.hasher(k)) { not_found {none} diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 89e9d0338fe..3369e95f1a3 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -79,6 +79,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { contains_key(self, key) } fn get(&&key: uint) -> V { get(self, key) } + fn [](&&key: uint) -> V { get(self, key) } fn find(&&key: uint) -> option<V> { find(self, key) } fn rehash() { fail } fn each(it: fn(&&uint, V) -> bool) { |
