← Back to context

Comment by ordu

11 hours ago

> 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?

Yes, destructuring is typically the only allowed way to get rid of linear/indestructible values. If the type has private fields, this is only possible in the same module, so commit(txn) and rollback(txn) would have to be implemented in the same module as the Transaction type.