streamweave
Core traits and types for StreamWeave
The foundational abstractions that power all StreamWeave data processing.
The streamweave package provides the core traits and types that form the foundation of the StreamWeave framework. All other StreamWeave packages depend on these core abstractions to build producers, transformers, and consumers.
β¨ Key Features
- Producer Trait: Define components that generate data streams
- Transformer Trait: Define components that transform data streams
- Consumer Trait: Define components that consume data streams
- Input/Output Traits: Type-safe stream interfaces
- Port System: Type-safe multi-port connections for graph-based processing
- Configuration System: Unified configuration for error handling and component naming
- Error Handling Integration: Seamless integration with
streamweave-error
π¦ Installation
Add this to your Cargo.toml:
[]
= "0.3.0"
π Quick Start
Basic Pipeline Example
use ;
// This example shows the core traits in action
// See specific package implementations for concrete examples
For a complete working example, see the pipeline package or check out the examples directory.
π API Overview
Producer Trait
The Producer trait defines components that generate data streams. Producers are the starting point of any StreamWeave pipeline.
use Producer;
Key Methods:
produce()- Generates the output streamwith_config()- Applies configuration (error strategy, name)handle_error()- Handles errors according to configured strategy
Example Producer Implementation:
use ;
use ErrorStrategy;
use Stream;
use Pin;
Transformer Trait
The Transformer trait defines components that transform data streams. Transformers process items as they flow through the pipeline.
use Transformer;
Key Methods:
transform()- Transforms the input stream into an output streamwith_config()- Applies configuration (error strategy, name)handle_error()- Handles errors according to configured strategy
Example Transformer Implementation:
use ;
use ErrorStrategy;
use StreamExt;
use Pin;
Consumer Trait
The Consumer trait defines components that consume data streams. Consumers are the end point of a pipeline.
use Consumer;
Key Methods:
consume()- Consumes the input stream (async)with_config()- Applies configuration (error strategy, name)handle_error()- Handles errors according to configured strategy
Example Consumer Implementation:
use ;
use ErrorStrategy;
use StreamExt;
use Pin;
use Arc;
use Mutex;
Input and Output Traits
The Input and Output traits define the stream interfaces for components.
Input Trait:
Output Trait:
These traits ensure type safety and enable components to be composed together in pipelines and graphs.
Port System
The port system enables type-safe multi-port connections in the Graph API. Ports are represented as tuples, allowing components to have multiple inputs or outputs.
use ;
// Single port
type SinglePort = ;
// Multiple ports
type MultiPort = ;
// Extract port types at compile time
type FirstPort = Type; // i32
type SecondPort = Type; // String
type ThirdPort = Type; // bool
The port system supports up to 12 ports per component, with compile-time type checking.
Configuration System
All components support configuration through ProducerConfig, TransformerConfig, and ConsumerConfig:
use ErrorStrategy;
// Configure error handling
let config = default
.with_error_strategy
.with_name;
let producer = producer.with_config;
Configuration Options:
error_strategy- How to handle errors (Stop, Skip, Retry, Custom)name- Component name for logging and metrics
π Usage Examples
Creating a Producer
use ;
use ErrorStrategy;
// Create a producer with error handling
let producer = new
.with_config;
Creating a Transformer
use ;
use ErrorStrategy;
// Create a transformer with error handling
let transformer = new
.with_config;
Creating a Consumer
use ;
use ErrorStrategy;
// Create a consumer with error handling
let consumer = new
.with_config;
Error Handling Strategies
All components support multiple error handling strategies:
use ErrorStrategy;
// Stop on first error (default)
Stop
// Skip errors and continue processing
Skip
// Retry up to N times
Retry
// Custom error handler
new_custom
ποΈ Architecture
The streamweave core package provides the foundational abstractions:
βββββββββββββββ
β Producer ββββproducesβββ> Stream<T>
βββββββββββββββ
β
β Stream flows through
βΌ
βββββββββββββββ
β Transformer ββββtransformsβββ> Stream<U>
βββββββββββββββ
β
β Stream flows through
βΌ
βββββββββββββββ
β Consumer ββββconsumesβββ> (writes, stores, etc.)
βββββββββββββββ
All components:
- Implement
Inputand/orOutputtraits for type safety - Support configuration for error handling and naming
- Integrate with the error handling system
- Can be used in both Pipeline and Graph APIs
π Dependencies
streamweave depends on:
tokio- Async runtimefutures- Stream abstractionsasync-trait- Async trait supportchrono- Timestamp supportstreamweave-error- Error handling system
π― Use Cases
The core traits are used to:
- Build Custom Components: Create producers, transformers, and consumers for specific use cases
- Type-Safe Composition: Ensure components can be safely connected in pipelines
- Error Handling: Provide consistent error handling across all components
- Graph API: Enable multi-port connections in complex topologies
- Configuration: Standardize component configuration and naming
π Error Handling
All components integrate with the streamweave-error package for consistent error handling:
- Error Strategies: Stop, Skip, Retry, or Custom handlers
- Error Context: Automatic error context creation with timestamps and component info
- Component Info: Automatic component identification for error reporting
β‘ Performance Considerations
- Zero-Cost Abstractions: Traits compile to efficient code with no runtime overhead
- Stream-Based: All processing is stream-based for memory efficiency
- Async: Full async/await support for concurrent processing
- Type Safety: Compile-time type checking prevents runtime errors
π Examples
For more examples, see:
- Pipeline Examples
- Graph Examples
- Package Implementations - See specific packages for concrete implementations
π Documentation
π See Also
- streamweave-error - Error handling system
- streamweave-pipeline - Pipeline builder and execution
- streamweave-graph - Graph API for complex topologies
- streamweave-message - Message envelope and metadata
π€ Contributing
Contributions are welcome! Please see the Contributing Guide for details.
π License
This project is licensed under the CC BY-SA 4.0 license.