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)]
|
||||
pub struct StaticMap<'a, K, V> {
|
||||
pub entries: &'a [(K,V)],
|
||||
}
|
||||
|
||||
impl<'a, K, V> StaticMap<'a, K, V>
|
||||
where K: Eq {
|
||||
impl<'a, K: Eq, V> StaticMap<'a, K, V> {
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn get<Q>(&self, key: &Q) -> Option<&V>
|
||||
where K: Borrow<Q> + std::cmp::PartialEq<Q>,
|
||||
Q: Eq {
|
||||
pub fn get(&self, key: &K) -> Option<&V> {
|
||||
for (ref k, ref v) in self.entries {
|
||||
if k == key { return Some(v) }
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue