We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cec259d commit 7e146ebCopy full SHA for 7e146eb
src/id.rs
@@ -145,3 +145,22 @@ impl<T> IntoIterator for Collection<T> {
145
self.0.into_iter()
146
}
147
148
+
149
+impl<Q, T> std::ops::Index<&Q> for Collection<T>
150
+where
151
+ Id<T>: std::borrow::Borrow<Q>,
152
+ Q: Eq + std::hash::Hash,
153
+{
154
+ type Output = T;
155
156
+ /// Returns a reference to the value corresponding to the supplied key.
157
+ ///
158
+ /// # Panics
159
160
+ /// Panics if the key is not present in the [Collection].
161
+ /// This can happens only if the key was removed from the collection at one point.
162
+ /// If no key are removed from the [Collection], you can safely use this method.
163
+ fn index(&self, k: &Q) -> &Self::Output {
164
+ &self.0[k]
165
+ }
166
+}
0 commit comments