Enum Effect 

Source
pub enum Effect<T> {
    Ok(T),
    Err(ErrorEffect),
    Retry {
        after: Duration,
        attempt: u32,
        max_attempts: u32,
        reason: String,
    },
    Compensate {
        action: CompensationAction,
        cause: Box<ErrorEffect>,
    },
    Pending {
        waiting_for: WaitCondition,
        resume_token: EventId,
        progress_hint: Option<Value>,
    },
    Batch(Vec<Effect<T>>),
}
Expand description

An effect represents the outcome of an operation.

Effects are more expressive than simple Result<T, E> because they can represent retry conditions, compensation actions, and pending states.

§Variants

  • Ok(T): Successful result
  • Err(ErrorEffect): Domain-level error (replayable, affects downstream)
  • Retry: Operation should be retried
  • Compensate: Compensation action is needed
  • Pending: Operation is waiting for something
  • Batch: Multiple effects (for fan-out scenarios)

Variants§

§

Ok(T)

Successful result

§

Err(ErrorEffect)

Domain-level error (must be persisted and handled)

§

Retry

Operation should be retried

Fields

§after: Duration

Duration to wait before retrying

§attempt: u32

Current attempt number (1-indexed)

§max_attempts: u32

Maximum number of attempts

§reason: String

Reason for retry

§

Compensate

Compensation action is needed

Fields

§action: CompensationAction

The action to take

§cause: Box<ErrorEffect>

The error that caused compensation

§

Pending

Operation is waiting for something

Fields

§waiting_for: WaitCondition

What the operation is waiting for

§resume_token: EventId

Token to resume when condition is met

§progress_hint: Option<Value>

Optimistic progress hint for UI (NOT authoritative state)

§

Batch(Vec<Effect<T>>)

Multiple effects (for fan-out scenarios)

Implementations§

Source§

impl<T> Effect<T>

Source

pub fn ok(value: T) -> Effect<T>

Create a successful effect.

Source

pub fn err(error: ErrorEffect) -> Effect<T>

Create an error effect.

Source

pub fn domain_error( error: DomainError, source_event: EventId, position: DagPosition, ) -> Effect<T>

Create a domain error effect.

Source

pub fn retry( after: Duration, attempt: u32, max_attempts: u32, reason: impl Into<String>, ) -> Effect<T>

Create a retry effect.

Source

pub fn pending(waiting_for: WaitCondition, resume_token: EventId) -> Effect<T>

Create a pending effect.

Source

pub fn is_ok(&self) -> bool

Check if this is a successful effect.

Source

pub fn is_err(&self) -> bool

Check if this is an error effect.

Source

pub fn needs_retry(&self) -> bool

Check if this effect requires retry.

Source

pub fn is_pending(&self) -> bool

Check if this effect is pending.

Source

pub fn into_result(self) -> Result<T, ErrorEffect>

Convert to a Result, losing retry/compensation information.

Source

pub fn map<U, F>(self, f: F) -> Effect<U>
where F: FnOnce(T) -> U + Clone,

Map the success value.

Source

pub fn unwrap(self) -> T

Extract the success value, panicking if not Ok.

Source

pub fn expect(self, msg: &str) -> T

Extract the success value, panicking with a custom message if not Ok.

Source

pub fn and_then<U, F>(self, f: F) -> Effect<U>
where F: FnOnce(T) -> Effect<U>,

Chain a function that returns an Effect on the success value.

If self is Ok(t), returns f(t). Otherwise, returns the original non-Ok effect unchanged.

Source

pub fn map_err<F>(self, f: F) -> Effect<T>

Map the error effect using a transformation function. Recurses into Batch to transform errors within each inner effect.

Source

pub fn or_else<F>(self, f: F) -> Effect<T>
where F: FnOnce(ErrorEffect) -> Effect<T> + Clone,

Handle an error by applying a recovery function. Recurses into Batch to recover errors within each inner effect.

Source

pub fn unwrap_or(self, default: T) -> T

Extract the success value or return a default.

If self is Ok(t), returns t. Otherwise, returns default.

Source

pub fn unwrap_or_else<F>(self, f: F) -> T
where F: FnOnce(ErrorEffect) -> T,

Extract the success value or compute a default from the error.

If self is Ok(t), returns t. Otherwise, returns f(e) where e is the error effect (or a synthesized one for non-error variants).

Trait Implementations§

Source§

impl<T> Clone for Effect<T>
where T: Clone,

Source§

fn clone(&self) -> Effect<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Effect<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de, T> Deserialize<'de> for Effect<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Effect<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, E> From<Result<T, E>> for Effect<T>
where E: Into<ErrorEffect>,

Source§

fn from(result: Result<T, E>) -> Effect<T>

Converts to this type from the input type.
Source§

impl<T> PartialEq for Effect<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Effect<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for Effect<T>
where T: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> ToSchema for Effect<T>
where T: ToSchema,

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference [utoipa::openapi::schema::Schema]s for this type. Read more
Source§

impl<T> StructuralPartialEq for Effect<T>

Auto Trait Implementations§

§

impl<T> Freeze for Effect<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Effect<T>
where T: RefUnwindSafe,

§

impl<T> Send for Effect<T>
where T: Send,

§

impl<T> Sync for Effect<T>
where T: Sync,

§

impl<T> Unpin for Effect<T>
where T: Unpin,

§

impl<T> UnwindSafe for Effect<T>
where 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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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.

§

impl<T> PartialSchema for T
where T: ComposeSchema + ?Sized,

§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,