Skip to content

Commit ef2cf4e

Browse files
mikolaichukshawntabrizi
authored andcommitted
change impl FnOnce() to generic type + trait bound (paritytech#11534)
* change impl FnOnce() to generic type + trait bound with_transaction() function can not be used with explicit generic arguments because of this issue: rust-lang/rust#83701 * make the same changes elsewhere Co-authored-by: Shawn Tabrizi <[email protected]>
1 parent b28f0a0 commit ef2cf4e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

frame/support/src/storage/transactional.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ pub fn is_transactional() -> bool {
101101
/// error.
102102
///
103103
/// Commits happen to the parent transaction.
104-
pub fn with_transaction<T, E>(f: impl FnOnce() -> TransactionOutcome<Result<T, E>>) -> Result<T, E>
104+
pub fn with_transaction<T, E, F>(f: F) -> Result<T, E>
105105
where
106106
E: From<DispatchError>,
107+
F: FnOnce() -> TransactionOutcome<Result<T, E>>,
107108
{
108109
// This needs to happen before `start_transaction` below.
109110
// Otherwise we may rollback the increase, then decrease as the guard goes out of scope
@@ -129,7 +130,10 @@ where
129130
/// This is mostly for backwards compatibility before there was a transactional layer limit.
130131
/// It is recommended to only use [`with_transaction`] to avoid users from generating too many
131132
/// transactional layers.
132-
pub fn with_transaction_unchecked<R>(f: impl FnOnce() -> TransactionOutcome<R>) -> R {
133+
pub fn with_transaction_unchecked<R, F>(f: F) -> R
134+
where
135+
F: FnOnce() -> TransactionOutcome<R>,
136+
{
133137
// This needs to happen before `start_transaction` below.
134138
// Otherwise we may rollback the increase, then decrease as the guard goes out of scope
135139
// and then end in some bad state.
@@ -163,9 +167,10 @@ pub fn with_transaction_unchecked<R>(f: impl FnOnce() -> TransactionOutcome<R>)
163167
/// This is the same as `with_transaction`, but assuming that any function returning
164168
/// an `Err` should rollback, and any function returning `Ok` should commit. This
165169
/// provides a cleaner API to the developer who wants this behavior.
166-
pub fn with_storage_layer<T, E>(f: impl FnOnce() -> Result<T, E>) -> Result<T, E>
170+
pub fn with_storage_layer<T, E, F>(f: F) -> Result<T, E>
167171
where
168172
E: From<DispatchError>,
173+
F: FnOnce() -> Result<T, E>,
169174
{
170175
with_transaction(|| {
171176
let r = f();
@@ -181,9 +186,10 @@ where
181186
///
182187
/// If we are already in a storage layer, we just execute the provided closure.
183188
/// If we are not, we execute the closure within a [`with_storage_layer`].
184-
pub fn in_storage_layer<T, E>(f: impl FnOnce() -> Result<T, E>) -> Result<T, E>
189+
pub fn in_storage_layer<T, E, F>(f: F) -> Result<T, E>
185190
where
186191
E: From<DispatchError>,
192+
F: FnOnce() -> Result<T, E>,
187193
{
188194
if is_transactional() {
189195
f()

0 commit comments

Comments
 (0)