pub struct TransactionHelper<T, F> { /* private fields */ }
Expand description
Helper for working with the new transasction interface.
This helper serves two purposes: to present a FnOnce
interface for transactions,
and to allow the extraction of data from within transactions.
§Extracting Data
The CoreCryptoCommand
interface requires some kind of interior mutability to extract
any data: it takes an immutable reference to the implementing item, and returns the unit struct
in the success case.
That pattern is relatively arcane and verbose, particularly when we just want to smuggle out some data from within the transaction. This helper is intended to ease and automate that process.
Use it like this (pseudocode):
// an extractor is always `Arc`-wrapped
let extractor: Arc<_> = TransactionHelper::new(move |context| async move {
// return whatever you need from the transaction here
});
core_crypto.transaction(extractor.clone()).await?;
let return_value = extractor.into_return_value();
§Panics
TransactionHelper
is a one-shot item. Attempting to use the
same extractor in two different transactions will cause a panic.
Implementations§
Source§impl<T, F, Fut> TransactionHelper<T, F>
impl<T, F, Fut> TransactionHelper<T, F>
pub fn new(func: F) -> Arc<Self>
Sourcepub fn into_return_value(self: Arc<Self>) -> T
pub fn into_return_value(self: Arc<Self>) -> T
Get the return value from the internal function.
§Panics
- If there exists more than one strong reference to this extractor
- If the inner function was never called
- If the inner function returned an
Err
variant
In general if you call this after a call like
core_crypto.transaction(extractor.clone())?;
then this will be fine.
Sourcepub fn try_into_return_value(self: Arc<Self>) -> Option<T>
pub fn try_into_return_value(self: Arc<Self>) -> Option<T>
Safely get the return value from the internal function.
If there exists more than one strong reference to this item, or
the inner function was never called or returned an Err
variant,
this will return None
.
Trait Implementations§
Source§impl<T, F, Fut> CoreCryptoCommand for TransactionHelper<T, F>
impl<T, F, Fut> CoreCryptoCommand for TransactionHelper<T, F>
Auto Trait Implementations§
impl<T, F> !Freeze for TransactionHelper<T, F>
impl<T, F> !RefUnwindSafe for TransactionHelper<T, F>
impl<T, F> Send for TransactionHelper<T, F>
impl<T, F> Sync for TransactionHelper<T, F>
impl<T, F> Unpin for TransactionHelper<T, F>
impl<T, F> UnwindSafe for TransactionHelper<T, F>where
F: UnwindSafe,
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
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more