diff --git a/src/map.rs b/src/map.rs index eecd55a1..b346b77d 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1031,6 +1031,18 @@ where } } + /// Return item index + pub fn entry_index(&self, key: &Q) -> Option + where + Q: Hash + Equivalent, + { + if let Some((_, found)) = self.find(key) { + Some(found) + } else { + None + } + } + pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> where Q: Hash + Equivalent, diff --git a/src/set.rs b/src/set.rs index 4b83f4b5..005e1ff5 100644 --- a/src/set.rs +++ b/src/set.rs @@ -327,6 +327,14 @@ where self.map.get_full(value).map(|(i, x, &())| (i, x)) } + /// Return item index + pub fn entry_index(&self, value: &Q) -> Option<(usize)> + where + Q: Hash + Equivalent, + { + self.map.entry_index(value) + } + /// Adds a value to the set, replacing the existing value, if any, that is /// equal to the given one. Returns the replaced value. ///