diff options
| author | bors <bors@rust-lang.org> | 2018-03-26 15:48:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-26 15:48:06 +0000 |
| commit | ab8b961677ac5c74762dcea955aa0ff4d7fe4915 (patch) | |
| tree | 11020d105058713d694130b47400ae11ba66f1d2 /src/liballoc | |
| parent | 13a86f4d8555702085b97de3a42234a82ddc045d (diff) | |
| parent | 1233aa29de2d6f5e293f84b38ba2b02cfaf1fa0e (diff) | |
| download | rust-ab8b961677ac5c74762dcea955aa0ff4d7fe4915.tar.gz rust-ab8b961677ac5c74762dcea955aa0ff4d7fe4915.zip | |
Auto merge of #49379 - TimNN:rollup, r=TimNN
Rollup of 7 pull requests - Successful merges: #48693, #48932, #49103, #49170, #49187, #49346, #49353 - Failed merges:
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/btree/map.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index ed9c8c18f0d..cada190032a 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -576,6 +576,33 @@ impl<K: Ord, V> BTreeMap<K, V> { } } + /// Returns the key-value pair corresponding to the supplied key. + /// + /// The supplied key may be any borrowed form of the map's key type, but the ordering + /// on the borrowed form *must* match the ordering on the key type. + /// + /// # Examples + /// + /// ``` + /// #![feature(map_get_key_value)] + /// use std::collections::BTreeMap; + /// + /// let mut map = BTreeMap::new(); + /// map.insert(1, "a"); + /// assert_eq!(map.get_key_value(&1), Some((&1, &"a"))); + /// assert_eq!(map.get_key_value(&2), None); + /// ``` + #[unstable(feature = "map_get_key_value", issue = "49347")] + pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)> + where K: Borrow<Q>, + Q: Ord + { + match search::search_tree(self.root.as_ref(), k) { + Found(handle) => Some(handle.into_kv()), + GoDown(_) => None, + } + } + /// Returns `true` if the map contains a value for the specified key. /// /// The key may be any borrowed form of the map's key type, but the ordering |
