I'm trying to some how unify simple SQL queries by generating appropriate strings. However I'm stuck with rusqlite params matching:
pub fn find_taglines(search_params: Option<(SearchType, String)>) -> Result<Vec<Tagline>>{
let conn = open_connection().unwrap();
let options: (String, &[&dyn ToSql]) = match search_params {
Some((search_type, value)) => {
(get_search_by_query(search_type), params![value])
},
None => (String::from(SELECT_QUERY), &[]),
};
and I get those errors:
error[E0716]: temporary value dropped while borrowed
--> src/models.rs:71:52
|
69 | let options: (String, &[&dyn ToSql]) = match search_params {
| ------- borrow later stored here
70 | Some((search_type, value)) => {
71 | (get_search_by_query(search_type), params![value])
| ^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
72 | },
| - temporary value is freed at the end of this statement
|
= note: consider using a `let` binding to create a longer lived value
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0597]: `value` does not live long enough
--> src/models.rs:71:52
|
69 | let options: (String, &[&dyn ToSql]) = match search_params {
| ------- borrow later stored here
70 | Some((search_type, value)) => {
71 | (get_search_by_query(search_type), params![value])
| ^^^^^^^^^^^^^^ borrowed value does not live long enough
72 | },
| - `value` dropped here while still borrowed
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 2 previous errors
So I'm not really sure how to solve it in context of rusqlite internal types.