-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(net): get
and peek
for LruCache
#8508
Conversation
let _ = self.inner.get(entry)?; | ||
self.iter().next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same as:
let _ = self.inner.get(entry)?; | |
self.iter().next() | |
let _ = self.inner.get(entry)?; | |
Some(entry) |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not if the types have a custom PartialEq
impl, consider type
struct MyType {
id: i32,
colour: i32,
}
impl PartialEq for MyType {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Hash ..
then we can have two instances with different colour, that will both have the same key
let green = MyType { id: 1, colour: 32 };
let blue = MyType { id: 1, colour: 34 };
let mut cache = LruCache::new();
cache.insert(green);
let _ = cache.get(&blue); // this will exist, but it will actually be green that is in the map
this extension to LruCache just makes it safe to use in the codebase kind of, cause we have a couple of types that impl custom PartialEq
on a subset of fields. using a HashMap
for these types makes way more sense though.
Adds methods
get
andpeek
to LruCache, which are needed for #6559