pub enum TxOutcome<T> {
Commit(T),
Rollback(T),
}Expand description
The outcome of a DbContext::transaction
closure.
Unlike DbContext::use_transaction,
which commits on Ok and rolls back only on Err, this type lets a handler
abort the database work and still return a successful business result.
ⓘ
let result = ctx.transaction(|ctx| Box::pin(async move {
// ... database work ...
if !meets_condition {
return Ok(TxOutcome::Rollback(BizResult::Rejected));
}
Ok(TxOutcome::Commit(BizResult::Done))
})).await?;Variants§
Commit(T)
Commit the transaction and return the value.
Rollback(T)
Roll the transaction back, detach tracked entities, and return the value.
Trait Implementations§
impl<T: Eq> Eq for TxOutcome<T>
impl<T: PartialEq> StructuralPartialEq for TxOutcome<T>
Auto Trait Implementations§
impl<T> Freeze for TxOutcome<T>where
T: Freeze,
impl<T> RefUnwindSafe for TxOutcome<T>where
T: RefUnwindSafe,
impl<T> Send for TxOutcome<T>where
T: Send,
impl<T> Sync for TxOutcome<T>where
T: Sync,
impl<T> Unpin for TxOutcome<T>where
T: Unpin,
impl<T> UnsafeUnpin for TxOutcome<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for TxOutcome<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more