spacejam/sled

Does Tree::transaction really need Fn instead of FnMut?

stevenroose opened this issue · 3 comments

Related: #1235.

Tree::transaction takes a closure that is Fn. This makes it impossible to move and consume variables inside the closure.

Fn is only needed if the closure has to be able to be called multiple times. Is that the case?

Could the closure be made FnMut or FnOnce otherwise

Tpt commented

Fn is only needed if the closure has to be able to be called multiple times. Is that the case?

Yes, in case of conflicts transaction are automatically aborted and restarted by Sled. So, the closure might be evaluated multiple times.

vi commented

Fn is only needed if the closure has to be able to be called multiple times.

the closure might be evaluated multiple times

This prevents FnOnce, but does not necessarily prevent FnMut.

Yeah but I agree to use Fn instead of FnMut because it's really not otherwise clear to the user. F.e. they might have a vector they want to store into the db and use drain or it or something and then on an abort the second time the vector is already partially drained.

In this case I agree on Fn.