I am using https://github.com/rusqlite/rusqlite to interface rust with SQLite. I have an object of type Connection
. This connection is held behind a RwLock
since the threadsafety mode of SQLite I'm using only guarantees inter-process threadsafety. I'm thus modelling the intra-process thread-safety with this lock.
I now want to explicitly close the connection using a wrapper function around my Project
class, which owns one such connection:
struct Project {
db: RwLock<Connection>
}
impl Project {
pub fn close(mut self) -> Result<(), ProjectError> {
self.db.write()?.close()?;
}
}
This however fails as Connection::close
has a signature of pub fn close(self) -> ...
with the following error:
cannot move out of dereference of `RwLockWriteGuard<'_, Connection>`
...
move occurs because value has type `Connection`, which does not implement the `Copy` trait
I understand the error but do not understand how can I work around it, since what I'm doing is technically sound.
I need the lock, I need to call the close
function explicitly (just dropping it doesn't work for me as I need to catch errors during shutdown for backup reasons). I also find rusqlite's decision to consume self
sensible and don't want to fork it.
Thanks in advance