From 7e280d4e6482a6b46147c1a7992ac93e70d67835 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 31 Dec 2017 10:15:41 +0000 Subject: [PATCH] Add comment to justify `&mut Connection` in `Transaction` The `Transaction` implementation never actually mutates the `Connection` reference we give it. In fact, the `Transaction` structure itself only requires an immutable connection. So it can be surprising to readers that the constructor requires a `&mut Connection`. We do this so as to prevent at compile-time nested or concurrent transactions on the same connection as these are not allowed by SQLite. In this commit, we add a comment explaining this nuance. --- src/transaction.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/transaction.rs b/src/transaction.rs index 41414f7..7e3e012 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -94,6 +94,9 @@ pub struct Savepoint<'conn> { impl<'conn> Transaction<'conn> { /// Begin a new transaction. Cannot be nested; see `savepoint` for nested transactions. + // Even though we don't mutate the connection, we take a `&mut Connection` + // so as to prevent nested or concurrent transactions on the same + // connection. pub fn new(conn: &mut Connection, behavior: TransactionBehavior) -> Result { let query = match behavior { TransactionBehavior::Deferred => "BEGIN DEFERRED",