Hello Rust World,
I'm new to Rust Lang; I'm coming from C++, and a few peculiarities of the language still pose problems for me.
I'm trying to create an interface to an SQLite DB using Rustqlite. I've made a basic method for handling generic requests, but I'm having trouble understanding the errors.
Code:
pub fn query_projects(&mut self, query: &str) -> Result<Rows<'_>> {
let mut stmt = self.conn.prepare(query)?;
let rows = stmt.query([]).unwrap();
Ok(rows)
}
Error:
Compiling myapp v0.1.0 (/home/jiel/rust/myapp)
error[E0515]: cannot return value referencing local variable `stmt`
--> src/database.rs:28:9
|
27 | let rows = stmt.query([]).unwrap();
| -------------- `stmt` is borrowed here
28 | Ok(rows)
| ^^^^^^^^ returns a value referencing data owned by the current function
For more information about this error, try `rustc --explain E0515`.
error: could not compile `myapp` due to previous error
Thank you for helping a new rust user.