pub struct Transaction { /* private fields */ }Expand description
Transaction wrapper that automatically rolls back and ends unfinished transaction once it goes out of scope.
§Example
Initiator:
let mut tx = Transaction::initiate(123, &[]);
// Do the changes here...
if tx.commit().is_err() {
// Rollback the changes here...
}
tx.end();Processor:
let (mut tx, payload, initiator_id) = Transaction::recv();
// Do the changes here...
if tx.commit().is_err() {
// Rollback the changes here...
}
tx.end();Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn initiate(
target: GuestId,
payload: &[u8],
) -> Result<Self, TransactionFailed>
pub fn initiate( target: GuestId, payload: &[u8], ) -> Result<Self, TransactionFailed>
Initiates a transaction with target providing the payload.
Wraps initiate_transaction.
Sourcepub fn recv_into(payload: &mut [u8]) -> Result<(Self, usize, GuestId), usize>
pub fn recv_into(payload: &mut [u8]) -> Result<(Self, usize, GuestId), usize>
Receives a transaction from the transaction initiator.
Copies the payload to payload.
Returns new Transaction instance, the size of the payload and the guest ID of the
initiator.
Wraps recv_transaction_into.
Sourcepub fn commit(&mut self) -> Result<(), TransactionFailed>
pub fn commit(&mut self) -> Result<(), TransactionFailed>
Commits the transaction.
Panics if the transaction has already been committed or rolled back.
Wraps commit_transaction.
Sourcepub fn rollback(&mut self)
pub fn rollback(&mut self)
Rolls back the transaction.
Panics if the transaction has already been committed or rolled back.
Wraps rollback_transaction.
Sourcepub fn end(self)
pub fn end(self)
Ends the transaction.
Panics if the transaction hasn’t been committed or rolled back.
Wraps end_transaction.