Why my rust function get an " returns a value referencing data owned by the current function" error?

I know I can't return a borrowed value from a function, but I don't know how to solve it. This is my function:

pub fn query(&self, sql: &str, params: &[&dyn ToSql]) -> Result<ResultSet<Row>, Error> {
    let pool = self.pool.clone();
    let con = pool.get().unwrap();
    let rows = con.query(sql, params).unwrap();

this is error:

error[E0515]: cannot return value referencing local variable `con`
  --> BloodTranslate\src\my_db\oracle_mod.rs:62:9
61 |         let rows = con.query(sql,params).unwrap();
   |                    --- `con` is borrowed here
62 |         Ok(rows)
   |         ^^^^^^^^ returns a value referencing data owned by the current function

Thanks a lot !!!

Read more here: https://stackoverflow.com/questions/67932818/why-my-rust-function-get-an-returns-a-value-referencing-data-owned-by-the-curr

Content Attribution

This content was originally published by Tofu Bait at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: