Trait TransformNode

Source
pub trait TransformNode<Input, Output, Error>: Send + Sync
where Input: Send + 'static, Output: Send + 'static, Error: Error + Send + Sync + 'static,
{ // Required methods fn prep<'life0, 'async_trait>( &'life0 self, input: Input, ) -> Pin<Box<dyn Future<Output = Result<Input, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn exec<'life0, 'async_trait>( &'life0 self, input: Input, ) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn post<'life0, 'async_trait>( &'life0 self, output: Output, ) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

A simplified transform node trait for functional data transformations

The TransformNode trait provides a simplified interface for creating nodes that follow a functional transformation pattern with explicit input and output types. Unlike the more general LifecycleNode, which operates on a shared context, a TransformNode transforms data directly from input to output.

Each TransformNode implements a three-phase lifecycle:

  1. prep: Validates and prepares the input data
  2. exec: Performs the main transformation from input to output
  3. post: Post-processes the output data

§Benefits of TransformNode

  • Simpler API focusing on data transformation
  • Direct error types specific to the node (vs. generic FloxideError)
  • Functional programming style with explicit input/output
  • Easier to compose and reason about

§Example

use async_trait::async_trait;
use floxide_transform::TransformNode;
use std::error::Error;

// Custom error type
#[derive(Debug)]
struct MyError(String);
impl std::fmt::Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl Error for MyError {}

// A transform node that converts strings to uppercase
struct UppercaseTransformer;

#[async_trait]
impl TransformNode<String, String, MyError> for UppercaseTransformer {
    async fn prep(&self, input: String) -> Result<String, MyError> {
        if input.trim().is_empty() {
            return Err(MyError("Input cannot be empty".to_string()));
        }
        Ok(input)
    }

    async fn exec(&self, input: String) -> Result<String, MyError> {
        Ok(input.to_uppercase())
    }

    async fn post(&self, output: String) -> Result<String, MyError> {
        Ok(format!("Processed: {}", output))
    }
}

Required Methods§

Source

fn prep<'life0, 'async_trait>( &'life0 self, input: Input, ) -> Pin<Box<dyn Future<Output = Result<Input, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Preparation phase

Source

fn exec<'life0, 'async_trait>( &'life0 self, input: Input, ) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execution phase

Source

fn post<'life0, 'async_trait>( &'life0 self, output: Output, ) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Post-execution phase

Implementors§