~vikanezrimaya/kittybox#11: 
Storage: transactions

Arbitrary post operations in a safe manner.

trait Storage {
    type Transaction: Transaction;

    /// Begin a new atomic transaction.
    async fn begin(&self) -> Self::Transaction;
}

trait Transaction: Storage {
    type PostGuard: TxnPostGuard;
    /// Commit the transaction.
    async fn commit(self) -> Result<()>;
    /// Rollback the transaction explicitly.
    ///
    /// Preferably, this would also happen on Drop.
    async fn rollback(self);

    /// Check a post out of the storage to update it.
    async fn get_for_update(&self, url: &str) -> Result<Self::PostGuard>;

    /// Finish an update of a post, atomically updating it.
    async fn finish_update(&self, guard: Self::PostGuard) -> Result<()>;
}

trait TxnPostGuard: DerefMut<serde_json::Value> {}
Status
REPORTED
Submitter
~vikanezrimaya
Assigned to
No-one
Submitted
9 months ago
Updated
9 months ago
Labels
feature