-
Notifications
You must be signed in to change notification settings - Fork 91
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
lifetime 'static
required?
#84
Comments
This is because the cache key is generated by making a tuple out of the function arguments, and the resulting cache key needs to be Clone + Hash. You can pass a use std::thread::sleep;
use std::time::Duration;
use cached::proc_macro::cached;
use cached::SizedCache;
/// Use an explicit cache-type with a custom creation block and custom cache-key generating block
#[cached(
type = "SizedCache<String, usize>",
create = "{ SizedCache::with_size(100) }",
convert = r#"{ format!("{}{}", a, b) }"#
)]
fn keyed(a: &str, b: &str) -> usize {
let size = a.len() + b.len();
sleep(Duration::new(size as u64, 0));
size
} |
By "you can ignore the type and create blocks" did you mean I don't need to include them? Or to ignore the ones from the example and include my own specific ones? When I leave them off I get:
And if needed, do I need both |
ah, right sorry -
|
That works thanks |
I'm getting the following error:
Why is it suggesting a static lifetime? Adding a static lifetime propagates the static requirement up the call chain. Where I finally get
error[E0759]: `data1` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
How can I fix this?
The text was updated successfully, but these errors were encountered: