Skip to content

Commit

Permalink
Merge pull request #829 from tisonkun/map-get-kv
Browse files Browse the repository at this point in the history
feat: impl Map get_key_value
  • Loading branch information
epage authored Feb 5, 2025
2 parents 8efc81e + 4605a64 commit fbc77ec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/toml/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ impl Map<String, Value> {
self.map.get_mut(key)
}

/// Returns the key-value pair matching the given key.
///
/// The 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.
#[inline]
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
{
self.map.get_key_value(key)
}

/// Inserts a key-value pair into the map.
///
/// If the map did not have this key present, `None` is returned.
Expand Down

0 comments on commit fbc77ec

Please sign in to comment.