I commented, in #49 which is closed, because I had a similar issue, but I thought it might not get caught up there, so I'm opening a new issue with that same comment.
I'm implementing r2d2::ManageConnection. One of its fn's, is_valid, borrows the connection, mutably. The purpose of the function is to check if the connection is still... valid. The way I want to do this is to query the SQL Server for the result of "SELECT 1" like it is suggested to do. The problem is that tiberius' SqlConnection consumes self when calling query, which inside is_valid can't happen, because it's already borrowed in this context. Any suggestions?
fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
let sql_str = "SELECT 1";
let stmt = conn.prepare(sql_str);
let future = conn
.query(stmt, &[])
.for_each(move |x| {
let result: i32 = x.get(0);
// ...
Ok(())
});
// now run the future and unwrap it
match future.wait() {
Ok(_) => { Ok(()) }
Err(tiberius_error) => Err(
MSSQLConnectionManagerError(Errors::WrappedTiberiusError(tiberius_error))
),
}
}
error[E0507]: cannot move out of borrowed content
--> src/persistence/mssql.rs:112:22
|
112 | let future = conn
| ^^^^ cannot move out of borrowed content
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
I commented, in #49 which is closed, because I had a similar issue, but I thought it might not get caught up there, so I'm opening a new issue with that same comment.
I'm implementing
r2d2::ManageConnection
. One of its fn's,is_valid
, borrows the connection, mutably. The purpose of the function is to check if the connection is still... valid. The way I want to do this is to query the SQL Server for the result of "SELECT 1" like it is suggested to do. The problem is that tiberius'SqlConnection
consumes self when callingquery
, which insideis_valid
can't happen, because it's already borrowed in this context. Any suggestions?