I can't seem to find anything about lifetimes for my specific situation. The search
function has correct lifetimes and works fine, but then the search_case_insensitive
function tells me the lifetime is too short, but I don't understand why.
pub fn search<'a>(query: &str, contents: &'a str) -> Vec<(&'a str, i32)> {
//do something
}
pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<(&'a str, i32)> {
return search(&query.to_lowercase(), &contents.to_lowercase());
}
I get:
error[E0597]: borrowed value does not live long enough
--> src/lib.rs:44:43
|
44 | return search(&query.to_lowercase(), &contents.to_lowercase());
| ^^^^^^^^^^^^^^^^^^^^^^^ - temporary value only lives until here
| |
| temporary value does not live long enough
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 43:1...
--> src/lib.rs:43:1
|
43 | pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<(&'a str, i32)> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: consider using a `let` binding to increase its lifetime
I have tried doing things like let c = contents
and using this new c
value instead but get the same issue.