-
Notifications
You must be signed in to change notification settings - Fork 16
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 with lifetime? #20
Comments
Hi Henning! Similarly to #18 or #19 this appears to be a question of whether At the moment the goal is: "Decorate a function with this one directive, and it will just work*", where *) if your function has a simple signature and returns somewhat plain objects so that we don't have to care about lifetimes, references, etc. Of course this is not enough for a generalized caching framework. That in turn would (I argue) torpedo the small and straight-forward feature set currently realized here. Given that using hashmaps is not very complex, in such a situation it seems easier for a developer to implement a small cache themselves. With respect to non-static cache for memoize, one problem is that - at the moment - the struct ComplexType(int32, String);
struct MySimpleCache<'a>(HashMap<&'a ComplexType, String>);
impl<'a> MySimpleCache<'a> {
fn business_logic(&mut self, arg: &'a ComplexType) -> &str {
// look up in own cache and/or recalculate.
}
} which gives you ultimate control and is not that complex either. I hope I grasped your issue correctly, and please let me know if you have specific ideas that I don't see yet! :-) All the best, |
I have a vague idea, at least for the use case for dynamic programming problems.
I wonder if one could write a function attribute which transforms this into:
|
Hey Lewin!
When writing a dynamic programming solution for Advent of Code I was really happy to find memoize!
But sadly it does not (yet) support the use case.
One reason is, that due to the current implementation references are not supported.
I don't have a good solution yet, but I wonder: What would it take to change memoize from global cache to a cache with a non-'static lifetime?
Cheers, Henning
The text was updated successfully, but these errors were encountered: