-
Book Overview & Buying
-
Table Of Contents
Rust Web Programming - Third Edition
By :
There are times when the state of a struct and certain processes are just not appropriate anymore. A nice, clear example would be a database transaction. While a database transaction is in progress, certain processes are appropriate, such as adding another operation to the transaction. You may also want to commit your transaction or roll it back. However, once we have committed our transaction, we cannot roll it back or add another operation to the transaction; we need another transaction for this. Considering this, I would want my compiler to check and ensure that I am not passing in a transaction into certain functions once the transaction is no longer in progress. The compiler will not only give me instant feedback, but it will also be safer, as it could be that only certain edge cases could cause a bug, increasing the chance of the bug slipping through tests. We can start by defining a state with our struct.