static_map: remove starnge type borrow
This commit is contained in:
parent
d11f14f77d
commit
3cd244b9fa
|
@ -1,25 +1,19 @@
|
||||||
use std::borrow::Borrow;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StaticMap<'a, K, V> {
|
pub struct StaticMap<'a, K, V> {
|
||||||
pub entries: &'a [(K,V)],
|
pub entries: &'a [(K,V)],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K, V> StaticMap<'a, K, V>
|
impl<'a, K: Eq, V> StaticMap<'a, K, V> {
|
||||||
where K: Eq {
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.entries.len()
|
self.entries.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get<Q>(&self, key: &Q) -> Option<&V>
|
pub fn get(&self, key: &K) -> Option<&V> {
|
||||||
where K: Borrow<Q> + std::cmp::PartialEq<Q>,
|
|
||||||
Q: Eq {
|
|
||||||
for (ref k, ref v) in self.entries {
|
for (ref k, ref v) in self.entries {
|
||||||
if k == key { return Some(v) }
|
if k == key { return Some(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue