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>
impl<TCapability, TError, TOutput> ActionEffect<TCapability, TError, TOutput>
Sourcepub fn New(
Function: Arc<dyn Fn(TCapability) -> Pin<Box<dyn Future<Output = Result<TOutput, TError>> + Send>> + Send + Sync>,
) -> Self
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.
Sourcepub async fn Apply(&self, Capability: TCapability) -> Result<TOutput, TError>where
TCapability: Clone,
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.
Sourcepub fn map<TNewOutput, F>(
self,
_Function: F,
) -> ActionEffect<TCapability, TError, TNewOutput>
pub fn map<TNewOutput, F>( self, _Function: F, ) -> ActionEffect<TCapability, TError, TNewOutput>
Transforms the output of an effect from TOutput to TNewOutput.
Trait Implementations§
Source§impl<TCapability, TError, TOutput> Clone for ActionEffect<TCapability, TError, TOutput>
impl<TCapability, TError, TOutput> Clone for ActionEffect<TCapability, TError, TOutput>
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> 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
Mutably borrows from an owned value. Read more