pub struct CausalAction { /* private fields */ }Expand description
A CausalAction represents an executable action that can be triggered in response to causal conditions.
In a causal state machine (CSM), actions are paired with causal states. When a causal state’s conditions are met (evaluated to true), the associated action is fired.
§Purpose
CausalAction encapsulates a function that performs a specific task, such as:
- Triggering alerts or alarms
- Logging events
- Sending notifications
- Executing control operations
§Usage
CausalAction is typically used in conjunction with CausalState in a state-action pair
within a causal state machine (CSM). The CSM evaluates states and, when conditions are met,
fires the associated actions.
§Example
use deep_causality::{ActionError, CausalAction};
fn get_alert_action() -> CausalAction {
let func = || {
println!("Alert triggered!");
Ok(())
};
let descr = "Action that triggers an alert";
let version = 1;
CausalAction::new(func, descr, version)
}Implementations§
Source§impl CausalAction
impl CausalAction
Sourcepub fn fire(&self) -> Result<(), ActionError>
pub fn fire(&self) -> Result<(), ActionError>
Executes the action function encapsulated by this CausalAction.
This method is typically called by a causal state machine (CSM) when the associated causal state’s conditions are met.
§Returns
Ok(())if the action executes successfullyErr(ActionError)if the action fails
§Example
use deep_causality::{ActionError, CausalAction};
// Create a CausalAction
let action = CausalAction::new(
|| { println!("Action executed!"); Ok(()) },
"Example action",
1
);
// Fire the action
match action.fire() {
Ok(()) => println!("Action completed successfully"),
Err(e) => println!("Action failed: {}", e),
}Source§impl CausalAction
impl CausalAction
Trait Implementations§
Source§impl Clone for CausalAction
impl Clone for CausalAction
Source§fn clone(&self) -> CausalAction
fn clone(&self) -> CausalAction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CausalAction
impl Debug for CausalAction
Auto Trait Implementations§
impl Freeze for CausalAction
impl RefUnwindSafe for CausalAction
impl Send for CausalAction
impl Sync for CausalAction
impl Unpin for CausalAction
impl UnwindSafe for CausalAction
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