The key moment that I have to call sqlite_ext_shutdown after call of sqlite3_close.
rusqlite::Connection calls sqlite3_close in the rusqlite::Connection::close and rusqlite::Connection::drop,
both take self, but in Drop implementation I receive &mut self, so code like this:
impl Drop for Db {
fn drop(&mut self) {
drop(self.conn);// or self.conn.close()
unsafe { sqlite_ext_shutdown(self.sqlite_ext) };
}
}
cause compile time error.
Obviously I can workaround this by using Option<rusqlite::Connection> or
may be Rc<RefCell<rusqlite::Connection>> and use swap,
but may be there is solution without overhead?
and find all places where struct Db go out of scope and call this method,
but how I prevent in future go of struct Db out of scope without calling of Db::close?
Is that guaranteed forever these days? I know that’s the current impl and there was talk about making that a formal guarantee but not sure if that happened.
I think the ManuallyDrop approach still seems preferable to me as it’s more obvious that something funky is going on. It also doesn’t depend on field declaration order and focuses the required ordering where it matters.