Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

behzadnouri
Copy link

- 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.

NonZeroUsize for capacity is very nonergonomic and prevents some
use-cases. For example a usize allows to disable caching by using
capacity zero. see: jeromefroe#165

This reverts commit 0e415ef.
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
Copy link
Author

@jeromefroe This will address the discussion here: #165 (comment)

cc @Yosi-Hezi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant