maidsafe / lru_time_cache

LRU cache settable via size or time to live
BSD 3-Clause "New" or "Revised" License
104 stars 46 forks source link

change `key: &Key` argument to use `Borrow` trait #80

Closed loggerhead closed 8 years ago

loggerhead commented 8 years ago

For example, the following code is not support:

let cache: LruCache<String, String> = LruCache::with_capacity(1);
cache.contains_key("foo");

Consider change the method declaration from

fn contains_key(&self, key: &Key) -> bool 

to

fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool 
    where Key: Borrow<Q>, Q: Ord
afck commented 8 years ago

I agree, also with #81! In general, we should get the API more in line with the standard library's maps. PRs are welcome. :slightly_smiling_face: