From 2a03c1ad4d967ae35f0d9edbc4965e082b8755f1 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 11 Jan 2018 16:52:32 -0800 Subject: [PATCH] Add DropBehavior::Panic to enforce intentional commit or rollback. --- src/transaction.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transaction.rs b/src/transaction.rs index 41414f7..ac03b24 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -26,6 +26,9 @@ pub enum DropBehavior { /// Do not commit or roll back changes - this will leave the transaction or savepoint /// open, so should be used with care. Ignore, + + /// Panic. Used to enforce intentional behavior during development. + Panic, } /// Old name for `Transaction`. `SqliteTransaction` is deprecated. @@ -192,6 +195,7 @@ impl<'conn> Transaction<'conn> { DropBehavior::Commit => self.commit_(), DropBehavior::Rollback => self.rollback_(), DropBehavior::Ignore => Ok(()), + DropBehavior::Panic => panic!("Transaction dropped unexpectedly."), } } } @@ -303,6 +307,7 @@ impl<'conn> Savepoint<'conn> { DropBehavior::Commit => self.commit_(), DropBehavior::Rollback => self.rollback(), DropBehavior::Ignore => Ok(()), + DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."), } } }