CausalEffectPropagationProcess

Struct CausalEffectPropagationProcess 

Source
pub struct CausalEffectPropagationProcess<Value, State, Context, Error, Log> {
    pub value: EffectValue<Value>,
    pub state: State,
    pub context: Option<Context>,
    pub error: Option<Error>,
    pub logs: Log,
}
Expand description

The fundamental unit of causal computation in DeepCausality.

CausalEffectPropagationProcess encapsulates the state of a computation moving through a causal graph. It unifies value propagation, state management, context awareness, error handling, and comprehensive logging into a single, monadic structure.

§Concepts

  • Value: The primary data being transformed (e.g., a signal, a decision).
  • State: Persistent data that evolves as the process moves through the graph (Markovian state).
  • Context: Read-only configuration or environment data available to all steps.
  • Error: A failure state that short-circuits further computation but preserves logs.
  • Logs: An append-only history of every step, essential for auditability and explainability.

§Rationale

In complex causal reasoning, it is not enough to just know the final result. We must know how that result was reached, what invalid states were encountered, and what context was active. This struct implements the Monad pattern to handle these concerns automatically, allowing users to focus on the domain logic (“Business Logic”) rather than plumbing (error checking, logging).

Fields§

§value: EffectValue<Value>

The current value of the computation.

§state: State

The current state of the process (e.g., accumulated risk, counters).

§context: Option<Context>

The optional execution context (e.g., global config, reference data).

§error: Option<Error>

The current error state. If Some, new bind operations will skip execution.

§logs: Log

The audit log containing the history of operations.

Implementations§

Source§

impl<Value: Debug, Error: Debug, Log: Debug + Display + LogSize> CausalEffectPropagationProcess<Value, (), (), Error, Log>

Source

pub fn explain(&self) -> String

Generates a human-readable explanation of the causal computation’s history.

This method iterates over the accumulated logs, providing a comprehensive history of the computation, including the final value and any errors.

§Returns

A String containing the formatted explanation.

Source§

impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>

Source

pub fn value(&self) -> &EffectValue<Value>

Source

pub fn state(&self) -> &State

Source

pub fn context(&self) -> &Option<Context>

Source

pub fn error(&self) -> &Option<Error>

Source

pub fn logs(&self) -> &Log

Source§

impl<Value, Error, Log> CausalEffectPropagationProcess<Value, (), (), Error, Log>
where Log: LogSize,

Source

pub fn is_ok(&self) -> bool

Source

pub fn is_err(&self) -> bool

Source§

impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where Log: LogAppend + Default, State: Clone, Context: Clone, Error: Clone,

Source

pub fn bind<F, NewValue>( self, f: F, ) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>
where F: FnOnce(EffectValue<Value>, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>, NewValue: Default,

Chains a stateful, context-aware computation.

This is the primary method for building Markovian process chains, as the function f receives the value, state, and context from the previous step.

Source§

impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where Log: Clone, Error: Clone,

Source

pub fn with_state( effect: CausalEffectPropagationProcess<Value, (), (), Error, Log>, initial_state: State, initial_context: Option<Context>, ) -> Self

Lifts a stateless effect into a stateful process by providing an initial state and context.

This is the primary entry point for starting a stateful computation chain from a simple, pre-existing effect.

§Arguments
  • effect: The stateless PropagatingEffect (where State and Context are ()).
  • initial_state: The starting state for the new process.
  • initial_context: The optional starting context for the new process.
§Returns

A new CausalEffectPropagationProcess ready for stateful operations.

Source§

impl<Value, State, Context> CausalEffectPropagationProcess<Value, State, Context, CausalityError, EffectLog>
where Value: Default + Clone + Debug, State: Default + Clone + Debug, Context: Clone + Debug,

Source

pub fn from_error(err: CausalityError) -> Self

Creates a new process that explicitly contains an error. The state is set to default.

Source

pub fn none() -> Self

Creates a new process with EffectValue::None, default state, and no error.

Source

pub fn pure(value: Value) -> Self

Lifts a pure value into a process with a default state.

Source

pub fn from_effect_value(effect_value: EffectValue<Value>) -> Self

Creates a new process from a given EffectValue. The state is set to default.

Source

pub fn from_value(value: Value) -> Self

Source

pub fn from_effect_value_with_log( value: EffectValue<Value>, logs: EffectLog, ) -> Self

Creates a new process from a given EffectValue and EffectLog. The state is set to default.

Source

pub fn from_value_with_log(value: Value, logs: EffectLog) -> Self

Source§

impl<Value, State, Context, Log> CausalEffectPropagationProcess<Value, State, Context, CausalityError, Log>
where Log: LogAppend + Default, State: Clone, Context: Clone,

Source

pub fn bind_or_error<F, NewValue>( self, f: F, err_msg: &str, ) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>
where F: FnOnce(Value, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>, NewValue: Default,

Chains a computation while automatically unwrapping the inner EffectValue.

If the EffectValue is None, this method short-circuits with a CausalityError containing the provided err_msg. This simplifies the common pattern of: bind -> match effect_value { Some(v) => f(v), None => Error }

Trait Implementations§

Source§

impl<Value: Clone, State: Clone, Context: Clone, Error: Clone, Log: Clone> Clone for CausalEffectPropagationProcess<Value, State, Context, Error, Log>

Source§

fn clone( &self, ) -> CausalEffectPropagationProcess<Value, State, Context, Error, Log>

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<Value: Debug, State: Debug, Context: Debug, Error: Debug, Log: Debug> Debug for CausalEffectPropagationProcess<Value, State, Context, Error, Log>

Source§

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

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

impl<Value: Debug, Error: Debug, Log: Debug> Display for CausalEffectPropagationProcess<Value, (), (), Error, Log>

Source§

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

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

impl<Value, State, Context, Error, Log> Intervenable<Value> for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where Log: LogAppend + LogAddEntry + Default, Value: Debug,

Source§

fn intervene(self, new_value: Value) -> Self

Overrides the value within an effectful computation. Read more
Source§

impl<Value: PartialEq, State: PartialEq, Context: PartialEq, Error: PartialEq, Log: PartialEq> PartialEq for CausalEffectPropagationProcess<Value, State, Context, Error, Log>

Source§

fn eq( &self, other: &CausalEffectPropagationProcess<Value, State, Context, Error, Log>, ) -> 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<Value, State, Context, Error, Log> StructuralPartialEq for CausalEffectPropagationProcess<Value, State, Context, Error, Log>

Auto Trait Implementations§

§

impl<Value, State, Context, Error, Log> Freeze for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: Freeze, Log: Freeze, Value: Freeze, Context: Freeze, Error: Freeze,

§

impl<Value, State, Context, Error, Log> RefUnwindSafe for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: RefUnwindSafe, Log: RefUnwindSafe, Value: RefUnwindSafe, Context: RefUnwindSafe, Error: RefUnwindSafe,

§

impl<Value, State, Context, Error, Log> Send for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: Send, Log: Send, Value: Send, Context: Send, Error: Send,

§

impl<Value, State, Context, Error, Log> Sync for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: Sync, Log: Sync, Value: Sync, Context: Sync, Error: Sync,

§

impl<Value, State, Context, Error, Log> Unpin for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: Unpin, Log: Unpin, Value: Unpin, Context: Unpin, Error: Unpin,

§

impl<Value, State, Context, Error, Log> UnwindSafe for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
where State: UnwindSafe, Log: UnwindSafe, Value: UnwindSafe, Context: UnwindSafe, Error: 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.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.