From 581b0390325cd52cafbc2f0a29068089b6e7d553 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 6 Feb 2020 11:55:04 -0500 Subject: [PATCH] Write db on WriteGuard drop --- youmubot-db/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/youmubot-db/src/lib.rs b/youmubot-db/src/lib.rs index ccf8576..974fc60 100644 --- a/youmubot-db/src/lib.rs +++ b/youmubot-db/src/lib.rs @@ -64,3 +64,14 @@ where (*self).0.borrow_data_mut() } } + +impl Drop for DBWriteGuard +where + T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned, +{ + fn drop(&mut self) { + if let Err(e) = self.0.save() { + dbg!(e); + } + } +}