sodium_rust/
transaction.rs

1use crate::impl_::transaction::Transaction as TransactionImpl;
2use crate::SodiumCtx;
3
4/// A scoped transaction marker.
5///
6/// An alternative to [`SodiumCtx::transaction`] that creates a struct
7/// that will create a new transaction in the given [`SodiumCtx`] and
8/// hold it open until the `Transaction` is dropped.
9pub struct Transaction {
10    impl_: TransactionImpl,
11}
12
13impl Transaction {
14    /// Create a new scoped transaction on the given context.
15    pub fn new(sodium_ctx: &SodiumCtx) -> Transaction {
16        Transaction {
17            impl_: TransactionImpl::new(&sodium_ctx.impl_),
18        }
19    }
20
21    /// Explicitly close this transaction.
22    ///
23    /// This transaction will close automatically when it goes out of
24    /// scope and is dropped. This `close` method is an optional way
25    /// to explicitly close the transaction before that.
26    pub fn close(&self) {
27        self.impl_.close();
28    }
29}