mirror of
https://github.com/isar/rusqlite.git
synced 2025-01-20 22:40:52 +08:00
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.
This commit is contained in:
parent
402d5340d5
commit
7e280d4e64
@ -94,6 +94,9 @@ pub struct Savepoint<'conn> {
|
|||||||
|
|
||||||
impl<'conn> Transaction<'conn> {
|
impl<'conn> Transaction<'conn> {
|
||||||
/// Begin a new transaction. Cannot be nested; see `savepoint` for nested transactions.
|
/// 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<Transaction> {
|
pub fn new(conn: &mut Connection, behavior: TransactionBehavior) -> Result<Transaction> {
|
||||||
let query = match behavior {
|
let query = match behavior {
|
||||||
TransactionBehavior::Deferred => "BEGIN DEFERRED",
|
TransactionBehavior::Deferred => "BEGIN DEFERRED",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user