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

memoize macro requires owned parameters #31

Open
haydnv opened this issue Nov 16, 2023 · 2 comments
Open

memoize macro requires owned parameters #31

haydnv opened this issue Nov 16, 2023 · 2 comments

Comments

@haydnv
Copy link

haydnv commented Nov 16, 2023

This is similar to #20 but narrower in scope. The HashMap or LruCache that stores memoized results only requires an owned key when a new value is inserted. Could the memoized function accept a borrowed key which implements Clone or maybe ToOwned? Then if the function signature is fn my_function(key: &String) -> Value the cache could call key.clone() or key.to_owned() only in the case of a cache insert.

@dermesser
Copy link
Owner

That's a great idea, I will take a look at it

@sanchopanca
Copy link

Also came here to ask would you consider generalizing Clone to ToOwned?

It would probably be a simple change if not for the fact that HashMap is used in the signatures of the __init and __getit functions.

I don't know a generic way to get the to_owned() return type, but if not the signatures, type inference should handle this just fine.

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

No branches or pull requests

3 participants