| ▲ | simonask 5 hours ago | |||||||||||||
For context, the reason this would be really nice is that it would enable API designs that catch certain kinds of errors.
Right now, you can't implement this API without choosing between either silently rolling back unless the user calls `commit()`, or panicking in the Drop impl for the transaction if the user didn't explicitly call either `commit()` or `rollback()`.Your only current choice is to use closures, which are much less composable, because you need a variant for each flavor: infallible, fallible, async fallibe, etc.
Ick.If instead the transaction is a must-move type, you would get a compiler error if you fail to call exactly one of either commit or rollback, and particularly you would be forced to consider what happens at every exit point (early-out via `?` no longer just forgets the transaction). Very nice. | ||||||||||||||
| ▲ | ordu 3 hours ago | parent [-] | |||||||||||||
> If instead the transaction is a must-move type, you would get a compiler error if you fail to call exactly one of either commit or rollback Can you elaborate how it may work? I mean if I create a function: fn fail_silently(txn: Transaction) {} then the calling code would pass the compiler, but this function presumably isn't, ok. But what can make these functions to pass: impl Transaction { pub fn commit(self) { ... } pub fn rollback(self) { ... } } Would you need to destructure self or what? | ||||||||||||||
| ||||||||||||||