core_crypto_ffi::context

Struct TransactionHelper

Source
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>
where F: FnOnce(Arc<CoreCryptoContext>) -> Fut + Send + Sync, Fut: Future<Output = Result<T, CoreCryptoError>> + Send, T: Send + Sync,

Source

pub fn new(func: F) -> Arc<Self>

Source

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.

Source

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>
where F: FnOnce(Arc<CoreCryptoContext>) -> Fut + Send + Sync, Fut: Future<Output = Result<T, CoreCryptoError>> + Send, T: Send + Sync,

Source§

fn execute<'life0, 'async_trait>( &'life0 self, context: Arc<CoreCryptoContext>, ) -> Pin<Box<dyn Future<Output = Result<(), CoreCryptoError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Will be called inside a transaction in CoreCrypto

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>
where T: Send, F: Send,

§

impl<T, F> Sync for TransactionHelper<T, F>
where T: Send + Sync, F: Send,

§

impl<T, F> Unpin for TransactionHelper<T, F>
where F: Unpin, T: Unpin,

§

impl<T, F> UnwindSafe for TransactionHelper<T, F>
where F: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T