From 42da88efea3a342af028794133fb1e162388046e Mon Sep 17 00:00:00 2001 From: michaelvlach Date: Thu, 24 Aug 2023 20:40:00 +0200 Subject: [PATCH 1/3] Update db.rs --- agdb/src/db.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agdb/src/db.rs b/agdb/src/db.rs index 67b8784ca..b6a087484 100644 --- a/agdb/src/db.rs +++ b/agdb/src/db.rs @@ -250,7 +250,10 @@ impl Db { /// Read transactions cannot be committed or rolled back but their main function is to ensure /// that the database data does not change during their duration. Through its generic /// parameters it also allows transforming the query results into a type `T`. - pub fn transaction(&self, f: impl Fn(&Transaction) -> Result) -> Result { + pub fn transaction( + &self, + mut f: impl FnMut(&Transaction) -> Result, + ) -> Result { let transaction = Transaction::new(self); f(&transaction) @@ -274,7 +277,7 @@ impl Db { /// results into a type `T`. pub fn transaction_mut>( &mut self, - f: impl Fn(&mut TransactionMut) -> Result, + mut f: impl FnMut(&mut TransactionMut) -> Result, ) -> Result { let mut transaction = TransactionMut::new(&mut *self); let result = f(&mut transaction); From b83676ebe0d41b35739a20c2c1b3075a9ff94322 Mon Sep 17 00:00:00 2001 From: michaelvlach Date: Thu, 24 Aug 2023 20:40:02 +0200 Subject: [PATCH 2/3] Update mod.rs --- agdb/tests/test_db/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agdb/tests/test_db/mod.rs b/agdb/tests/test_db/mod.rs index 97db60191..327412d45 100644 --- a/agdb/tests/test_db/mod.rs +++ b/agdb/tests/test_db/mod.rs @@ -96,7 +96,7 @@ impl TestDb { #[track_caller] pub fn transaction_mut + std::fmt::Debug>( &mut self, - f: impl Fn(&mut TransactionMut) -> Result, + f: impl FnMut(&mut TransactionMut) -> Result, ) { self.db.transaction_mut(f).unwrap(); } @@ -107,7 +107,7 @@ impl TestDb { E: From + std::fmt::Debug + PartialEq, >( &mut self, - f: impl Fn(&mut TransactionMut) -> Result, + f: impl FnMut(&mut TransactionMut) -> Result, error: E, ) { assert_eq!(self.db.transaction_mut(f).unwrap_err(), error); From cf1fcfea4e73dd68e672bc97a490aabaa02b6319 Mon Sep 17 00:00:00 2001 From: michaelvlach Date: Thu, 24 Aug 2023 20:40:04 +0200 Subject: [PATCH 3/3] Update queries.md --- docs/queries.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/queries.md b/docs/queries.md index 60f48f3f3..7e0aea8a7 100644 --- a/docs/queries.md +++ b/docs/queries.md @@ -181,10 +181,10 @@ You can run a series of queries as a transaction invoking corresponding methods ```Rust impl Db { // immutable transactions - pub fn transaction(&self, f: impl Fn(&Transaction) -> Result) -> Result + pub fn transaction(&self, mut f: impl FnMut(&Transaction) -> Result) -> Result // mutable transactions - pub fn transaction_mut>(&mut self, f: impl Fn(&mut TransactionMut) -> Result) -> Result + pub fn transaction_mut>(&mut self, mut f: impl FnMut(&mut TransactionMut) -> Result) -> Result } ```