diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 00d4a5e6b316..21fe5163bb5f 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -45,6 +45,9 @@ iface map { "] 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 { alt self.search_tbl(k, self.hasher(k)) { not_found {none} diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 89e9d0338fe4..3369e95f1a3e 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -79,6 +79,7 @@ impl of map::map for smallintmap { contains_key(self, key) } fn get(&&key: uint) -> V { get(self, key) } + fn [](&&key: uint) -> V { get(self, key) } fn find(&&key: uint) -> option { find(self, key) } fn rehash() { fail } fn each(it: fn(&&uint, V) -> bool) {