Returns a reference to the value corresponding to the key. Implicitly converts between int and uint keys.
(&self, key: &(dyn AsKeyRef + '_))
| 65 | /// Returns a reference to the value corresponding to the key. Implicitly converts between int |
| 66 | /// and uint keys. |
| 67 | pub fn get(&self, key: &(dyn AsKeyRef + '_)) -> Option<&Value> { |
| 68 | self.map.get(key).or_else(|| { |
| 69 | // Also check keys that are cross type comparable. |
| 70 | let keyref = key.as_keyref(); |
| 71 | match keyref { |
| 72 | KeyRef::Int(k) => { |
| 73 | let converted = u64::try_from(k).ok()?; |
| 74 | self.map.get(&Key::Uint(converted)) |
| 75 | } |
| 76 | KeyRef::Uint(k) => { |
| 77 | let converted = i64::try_from(k).ok()?; |
| 78 | self.map.get(&Key::Int(converted)) |
| 79 | } |
| 80 | _ => None, |
| 81 | } |
| 82 | }) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #[derive(Debug, Eq, PartialEq, Hash, Ord, Clone, PartialOrd)] |
no test coverage detected