Closed xrl closed 9 years ago
Thanks for the pull request, and welcome! The contain-rs team is excited to review your changes, and you should hear from @huonw (or someone else) soon.
If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.
Thanks!
Can you make the signature of this method
fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Eq + Hash
in order to match get_mut
?
Also, it's not clear to me whether this should affect the LRU state of the key. @Gankro can weigh in on that, but in any case, the behavior in that regard should be documented (see the iter
method for an example).
Sure thing, changes pushed up.
One thing, I'm not sure why the documentation code with a number literal needed a &
to pass. Any ideas? I'm kind of lost on the purpose of the type sigs.
Thanks. I'm just waiting to hear about the LRU stuff.
As for the need for &
: It's because contains_key
's key
argument is of type &Q
, which means it's a reference to some type Q
. In this case, because the cache is storing integer (i32
) keys, contains_key
expects an argument that can be borrowed to &i32
. The integer literal 1
by itself is of type i32
, which is not a reference type, so the &
operator is needed to get an &i32
. The guide has more info.
Cool, thanks for the explanation. That makes sense.
I would assume contains_key should have the same behaviour as get
since it's always a trivial wrapper?
@Gankro I agree, though that requires contains_key
to take &mut self
and defer to self.get_mut()
(which is fine).
What do I need to do to make this useful for merging?
@xrl Sorry for the delay. Can you change the contains_key
method to take &mut self
and reimplement it as self.get_mut(key).is_some()
? Once you do that and squash the commits, it should be ready to merge. Thanks!
Bingo-bango. Take a look now.
And please push this version up to crates so I can do my own release. Thanks!
Thanks!
I want to make LruCache a drop in replacement for my needs, this was the only feature missing.