ActionEffect

Struct ActionEffect 

Source
pub struct ActionEffect<TCapability, TError, TOutput> {
    pub Function: Arc<dyn Fn(TCapability) -> Pin<Box<dyn Future<Output = Result<TOutput, TError>> + Send>> + Send + Sync>,
}
Expand description

An ActionEffect encapsulates an asynchronous operation as a first-class value.

It is a data structure that contains a function. This function, when provided with its required capability (TCapability), produces a Future that will yield the result of the operation. This pattern cleanly separates the definition of an operation from its execution.

§Type Parameters

  • TCapability: The type of the capability (e.g., Arc<dyn FileSystemReader>) that the effect’s closure requires to run.
  • TError: The error type that the effect’s operation can return.
  • TOutput: The success output type of the effect’s operation.

Fields§

§Function: Arc<dyn Fn(TCapability) -> Pin<Box<dyn Future<Output = Result<TOutput, TError>> + Send>> + Send + Sync>

The wrapped asynchronous function. It is stored in an Arc to make the ActionEffect struct itself cheap to clone.

Implementations§

Source§

impl<TCapability, TError, TOutput> ActionEffect<TCapability, TError, TOutput>

Source

pub fn New( Function: Arc<dyn Fn(TCapability) -> Pin<Box<dyn Future<Output = Result<TOutput, TError>> + Send>> + Send + Sync>, ) -> Self

Creates a new ActionEffect from a given function closure.

Source

pub async fn Apply(&self, Capability: TCapability) -> Result<TOutput, TError>
where TCapability: Clone,

Applies the effect by executing its wrapped function with the provided capability. This is typically called by an ApplicationRunTime.

Source

pub fn map<TNewOutput, F>( self, _Function: F, ) -> ActionEffect<TCapability, TError, TNewOutput>
where TCapability: 'static + Send, TError: 'static, TOutput: 'static + Send, TNewOutput: 'static, F: Fn(TOutput) -> TNewOutput + Send + Sync + 'static + Copy,

Transforms the output of an effect from TOutput to TNewOutput.

Trait Implementations§

Source§

impl<TCapability, TError, TOutput> Clone for ActionEffect<TCapability, TError, TOutput>

Source§

fn clone(&self) -> Self

Clones the ActionEffect. This is a cheap operation as it only clones the Arc pointer to the underlying function.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<TCapability, TError, TOutput> Freeze for ActionEffect<TCapability, TError, TOutput>

§

impl<TCapability, TError, TOutput> !RefUnwindSafe for ActionEffect<TCapability, TError, TOutput>

§

impl<TCapability, TError, TOutput> Send for ActionEffect<TCapability, TError, TOutput>

§

impl<TCapability, TError, TOutput> Sync for ActionEffect<TCapability, TError, TOutput>

§

impl<TCapability, TError, TOutput> Unpin for ActionEffect<TCapability, TError, TOutput>

§

impl<TCapability, TError, TOutput> !UnwindSafe for ActionEffect<TCapability, TError, TOutput>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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