Skip to content

Commit 008828f

Browse files
committed
Adds get_index to map.rs
1 parent d3eb7cd commit 008828f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/map.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,19 @@ where
10311031
}
10321032
}
10331033

1034+
/// Return item index
1035+
pub fn get_index<Q: ?Sized>(&self, key: &Q) -> Option<usize>
1036+
where
1037+
Q: Hash + Equivalent<K>,
1038+
{
1039+
if let Some((_, found)) = self.find(key) {
1040+
let entry = &self.core.entries[found];
1041+
Some(found)
1042+
} else {
1043+
None
1044+
}
1045+
}
1046+
10341047
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
10351048
where
10361049
Q: Hash + Equivalent<K>,

0 commit comments

Comments
 (0)