dataflow_rs/engine/functions/
mod.rs

1use crate::engine::error::Result;
2use crate::engine::message::{Change, Message};
3use async_trait::async_trait;
4use datalogic_rs::DataLogic;
5use std::sync::Arc;
6
7pub mod config;
8pub use config::FunctionConfig;
9
10pub mod validation;
11pub use validation::{ValidationConfig, ValidationRule};
12
13pub mod map;
14pub use map::{MapConfig, MapMapping};
15
16// Re-export all built-in functions for easier access
17pub mod builtins {
18    use super::*;
19
20    // Get all built-in functions with their standard names
21    pub fn get_all_functions() -> Vec<(String, Box<dyn AsyncFunctionHandler + Send + Sync>)> {
22        // Map and Validate are now internal to the Engine for better performance
23        // They can directly access compiled logic cache
24        // Add other built-in functions here as needed (HTTP, File I/O, etc.)
25        vec![]
26    }
27}
28
29/// Async interface for task functions that operate on messages
30///
31/// ## Usage
32///
33/// Implement this trait for custom processing logic.
34/// The function receives:
35/// - Mutable access to the message being processed (no cloning needed!)
36/// - Pre-parsed function configuration
37/// - Reference to the DataLogic instance for JSONLogic evaluation
38///
39/// ## Performance Note
40///
41/// This trait works directly with `&mut Message` without any cloning.
42/// The message is passed by mutable reference throughout the async execution,
43/// ensuring zero-copy operation for optimal performance.
44#[async_trait]
45pub trait AsyncFunctionHandler: Send + Sync {
46    /// Execute the function on a message with pre-parsed configuration
47    ///
48    /// # Arguments
49    ///
50    /// * `message` - The message to process (mutable reference, no cloning)
51    /// * `config` - Pre-parsed function configuration
52    /// * `datalogic` - Reference to DataLogic instance for JSONLogic evaluation
53    ///
54    /// # Returns
55    ///
56    /// * `Result<(usize, Vec<Change>)>` - Result containing status code and changes, or error
57    async fn execute(
58        &self,
59        message: &mut Message,
60        config: &FunctionConfig,
61        datalogic: Arc<DataLogic>,
62    ) -> Result<(usize, Vec<Change>)>;
63}