jeromefroe / lru-rs

An implementation of a LRU cache
https://docs.rs/lru/
MIT License
644 stars 106 forks source link

adds value-wrapper for borrowed or owned return values #177

Open behzadnouri opened 1 year ago

behzadnouri commented 1 year ago
- This is on top of:
- https://github.com/jeromefroe/lru-rs/pull/176
- Only the last commit is new code.
- I will rebase once #176 is merged.

get_or_insert, get_or_insert_mut and try_get_or_insert may return None only in the case where capacity is zero. Instead this commit adds a ValueWrapper:

enum ValueWrapper<'a, V> {
    Borrowed(&'a V),
    Owned(V),
}

which makes it possible for these methods to always return a value which can be borrowed as V.

behzadnouri commented 1 year ago

@jeromefroe This will address the discussion here: https://github.com/jeromefroe/lru-rs/issues/165#issuecomment-1660991681

cc @Yosi-Hezi