Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

High-performance workflow engine for message processing.

§Architecture

The engine features a modular design optimized for both IO-bound and CPU-bound workloads:

  • Separation of Concerns: Compiler handles pre-compilation, Executor handles runtime
  • Direct DataLogic: Single DataLogic instance per engine for zero contention
  • Immutable Workflows: All workflows compiled and cached at initialization
  • Pre-compiled Logic: JSONLogic expressions compiled once for optimal performance

§Performance Characteristics

  • Zero Runtime Compilation: All logic compiled during initialization
  • Cache-Friendly: Compiled logic stored in contiguous memory
  • Predictable Latency: No runtime allocations for logic evaluation
  • Thread-Safe Design: Applications can safely use multiple engine instances across threads

Implementations§

Source§

impl Engine

Source

pub fn new( workflows: Vec<Workflow>, custom_functions: Option<HashMap<String, Box<dyn FunctionHandler + Send + Sync>>>, retry_config: Option<RetryConfig>, ) -> Self

Creates a new Engine instance with configurable parameters.

§Arguments
  • workflows - The workflows to use for processing messages
  • custom_functions - Optional custom function handlers (None uses empty map)
  • include_builtins - Optional flag to include built-in functions (defaults to true if None)
  • retry_config - Optional retry configuration (uses default if None)
§Example
use dataflow_rs::{Engine, Workflow};

let workflows = vec![Workflow::from_json(r#"{"id": "test", "name": "Test", "priority": 0, "tasks": []}"#).unwrap()];

// Simple usage with defaults
let mut engine = Engine::new(workflows.clone(), None, None);
Source

pub fn new_with_shared_functions( workflows: Vec<Workflow>, task_functions: Arc<HashMap<String, Box<dyn FunctionHandler + Send + Sync>>>, retry_config: Option<RetryConfig>, ) -> Self

Creates a new Engine instance with shared function handlers. This is useful when creating multiple engine instances that share the same function registry.

§Arguments
  • workflows - The workflows to use for processing messages
  • task_functions - Shared function handlers wrapped in Arc
  • retry_config - Optional retry configuration (uses default if None)
Source

pub fn process_message(&mut self, message: &mut Message) -> Result<()>

Processes a message through workflows that match their conditions.

This method:

  1. Iterates through workflows sequentially in deterministic order (sorted by ID)
  2. Evaluates conditions for each workflow right before execution
  3. Executes matching workflows one after another (not concurrently)
  4. Updates the message with processing results and audit trail
  5. Clears the evaluation arena after processing to prevent memory leaks

Workflows are executed sequentially because later workflows may depend on the results of earlier workflows, and their conditions may change based on modifications made by previous workflows.

§Arguments
  • message - The message to process
§Returns
  • Result<()> - Success or an error if processing failed

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.