diff options
| author | Michael Sullivan <sully@msully.net> | 2012-06-27 16:34:53 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2012-06-27 16:35:05 -0700 |
| commit | df9b43e27cf112d197ed6173e16c136f4e31138f (patch) | |
| tree | 17c2958306676e12add7789bf77adca6a9b71f69 /src/libstd | |
| parent | 0c42a3ffee8e5943cbe9783f924c467069c5e0c3 (diff) | |
| download | rust-df9b43e27cf112d197ed6173e16c136f4e31138f.tar.gz rust-df9b43e27cf112d197ed6173e16c136f4e31138f.zip | |
Add an overloaded [] function to the map interface. Closes #2730.
Diffstat (limited to 'src/libstd')
| -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) { |
