| Crates.io | deep_causality_core |
| lib.rs | deep_causality_core |
| version | 0.0.5 |
| created_at | 2025-12-12 07:26:18.724034+00 |
| updated_at | 2026-01-22 07:35:50.979792+00 |
| description | Core types for deep_causality crate. |
| homepage | |
| repository | https://github.com/deepcausality/deep_causality.rs |
| max_upload_size | |
| id | 1981122 |
| size | 109,078 |
Core types and abstractions for the DeepCausality project.
This crate provides the foundational building blocks for causal reasoning, effect propagation, and mission-critical control flow construction. It is designed for high-assurance systems, supporting no_std, zero-allocation execution, and embedded requirements.
deep_causality_core provides two distinct, powerful abstractions for structuring complex logic. They can be used
independently.
ControlFlowBuilder: For Correct-by-Construction SystemsT to an input of type
T. This eliminates an entire class of runtime integration errors.strict-zst feature, it guarantees zero heap allocations and no
dynamic dispatch in the execution path, making it suitable for environments requiring formal verification and WCET
analysis (Worst-Case Execution Time).PropagatingEffect (stateless) and PropagatingProcess (stateful).bind), state
propagation, context-awareness, and causal interventions.deep_causality library.How to Choose:
ControlFlowBuilder.deep_causality crate.The crate defines the core types for modeling causal systems using Monadic Effect Systems.
CausalEffectSystem: The central runtime for managing causal models.CausalMonad: A monadic interface for chaining causal effects, allowing for composable and testable logic.PropagatingEffect / PropagatingProcess: Types that model how effects ripple through a system, integrated with Higher-Kinded Types (HKT) via deep_causality_haft.The Control Flow Builder is a specialized tool for constructing Correct-by-Construction execution graphs. It is designed for safety-critical applications where runtime wiring errors are unacceptable.
execute method accepts a pre-allocated queue, ensuring deterministic execution timing suitable for real-time control loops.This crate is designed to scale from research prototypes to certified flight control systems. The feature flags control the trade-off between flexibility and strict safety guarantees.
| Feature | Default | Description | Safety & Regulatory Implication |
|---|---|---|---|
std |
Yes | Enables standard library support. | General Purpose. Suitable for servers, desktops, and research. Not for bare-metal embedded. |
alloc |
Yes | Enables heap allocation (Vec, Box). |
Embedded Linux / RTOS. Required for dynamic graph construction. Most embedded systems use this. |
strict-zst |
No | Certification Mode. Enforces Zero-Sized Types. | Safety-Critical / Hard Real-Time. See below. |
strict-zst FeatureWhen strict-zst is enabled, the ControlFlowBuilder enforces that all user-provided logic must be Zero-Sized Types (ZSTs) (i.e., static function items).
dyn Fn), simplifying WCET (Worst-Case Execution Time) analysis.Recommendation:
strict-zst for final deployment in safety-critical environments where dynamic allocation and hidden state are impermissible.use deep_causality_core::{ControlFlowBuilder, ControlFlowProtocol, FromProtocol, ToProtocol};
use std::collections::VecDeque;
// 1. Define your Domain Protocol
#[derive(Clone, Debug)]
enum MyProtocol {
Signal(bool),
Command(u8),
}
// ... impl ControlFlowProtocol, FromProtocol, ToProtocol ...
fn sensor_read(input: bool) -> u8 {
if input { 100 } else { 0 }
}
fn main() {
let mut builder = ControlFlowBuilder::<MyProtocol>::default();
// 2. Add Nodes (Type-checked!)
let n_sensor = builder.add_node(sensor_read);
// 3. Build Graph
let graph = builder.build();
// 4. Execute (Zero-Allocation Loop)
let mut queue = VecDeque::with_capacity(10); // Pre-allocate memory
let input = true.to_protocol();
let result = graph.execute(input, 0, 10, &mut queue);
println!("Result: {:?}", result);
}
PropagatingEffect is a monadic container for stateless causal effects. It supports standard functional transformations (map, bind) via the Functor and Monad traits.
use deep_causality_core::{PropagatingEffect, PropagatingEffectWitness};
use deep_causality_haft::{Functor, Applicative};
fn main() {
// Create a pure effect
let effect = PropagatingEffectWitness::pure(10);
// Transform value (Functor)
let mapped = PropagatingEffectWitness::fmap(effect, |x| x * 2);
println!("Result: {:?}", mapped.value); // Value(20)
}
PropagatingProcess extends PropagatingEffect with State and Context. It allows you to model Markovian processes where each step can read/write state and access configuration context.
use deep_causality_core::{PropagatingProcess, PropagatingEffectWitness, EffectValue};
use deep_causality_haft::Applicative;
#[derive(Clone, Default, Debug)]
struct State { count: i32 }
fn main() {
// Lift a pure effect into a stateful process
let effect = PropagatingEffectWitness::pure(10);
let process = PropagatingProcess::with_state(effect, State::default(), None);
// Chain stateful computation
let next = process.bind(|val, mut state, ctx| {
state.count += 1;
deep_causality_core::CausalEffectPropagationProcess {
value: EffectValue::Value(val.into_value().unwrap() + 1),
state,
context: ctx,
error: None,
logs: Default::default(),
}
});
println!("State: {:?}", next.state); // State { count: 1 }
}
DeepCausality Core supports Causal Interventions (Pearl's "Do-calculus"). You can intervene on a running process to override values and simulate counterfactual scenarios ("What if X had been Y?").
The Intervenable trait adds the .intervene(value) method to both PropagatingEffect and PropagatingProcess.
use deep_causality_core::{PropagatingEffectWitness, Intervenable};
// 1. Create a factual effect
let effect = PropagatingEffectWitness::pure(10);
// 2. Intervene to force a new value (Counterfactual)
// This preserves logs and error states but overrides the value.
let counterfactual = effect.intervene(42);
To use this crate in a bare-metal no_std environment:
[dependencies]
deep_causality_core = { version = "...", default-features = false, features = ["alloc"] }
If you need absolute strictness (no Box<dyn Fn>):
[dependencies]
deep_causality_core = { version = "...", default-features = false, features = ["alloc", "strict-zst"] }
This project is licensed under the MIT license.
For details about security, please read the security policy.