use super::Receipts;
use std::path::Path;
pub struct OwnedReceipts(Receipts);
impl OwnedReceipts {
pub async fn open(state: &Path, repo: &Path) -> Result<Self, String> {
Receipts::open(state, repo).await.map(Self)
}
}
impl std::ops::Deref for OwnedReceipts {
type Target = Receipts;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Drop for OwnedReceipts {
fn drop(&mut self) {
let connection = self.0.connection.inner.clone();
let closed = std::thread::spawn(move || {
tokio::runtime::Builder::new_current_thread()
.build()
.expect("create the test writer's teardown runtime")
.block_on(connection.close())
})
.join();
if !std::thread::panicking() {
closed
.expect("join the test writer's teardown")
.expect("close the test writer's SQLite connection");
}
}
}