streamweave-vec
Vector producer and consumer for StreamWeave
Produce from and consume to dynamic vectors with flexible size handling.
The streamweave-vec package provides vector-based producers and consumers for StreamWeave. It enables reading from vectors and writing to vectors with dynamic size handling.
✨ Key Features
- VecProducer: Produce items from vectors
- VecConsumer: Consume items into vectors
- Dynamic Size: Vector size determined at runtime
- Capacity Management: Pre-allocate capacity for performance
- Order Preservation: Items preserved in order
📦 Installation
Add this to your Cargo.toml:
[]
= "0.3.0"
🚀 Quick Start
Produce from Vector
use VecProducer;
use PipelineBuilder;
let data = vec!;
let producer = new;
let pipeline = new
.producer
.consumer;
pipeline.run.await?;
Consume to Vector
use VecConsumer;
use PipelineBuilder;
let consumer = new;
let pipeline = new
.producer
.consumer;
pipeline.run.await?;
let vec = consumer.into_vec;
📖 API Overview
VecProducer
Produces items from a vector:
Key Methods:
new(data)- Create producer from vectorwith_error_strategy(strategy)- Set error handling strategywith_name(name)- Set component nameproduce()- Generate stream from vector
VecConsumer
Consumes items into a vector:
Key Methods:
new()- Create consumerwith_capacity(capacity)- Pre-allocate capacitywith_error_strategy(strategy)- Set error handling strategywith_name(name)- Set component nameconsume(stream)- Collect items into vectorinto_vec()- Get collected vector
📚 Usage Examples
Vector Transformation Pipeline
Transform vector elements:
use ;
use PipelineBuilder;
let input = vec!;
let producer = new;
let consumer = with_capacity;
let pipeline = new
.producer
.transformer // Double each element
.consumer;
pipeline.run.await?;
Pre-allocated Capacity
Pre-allocate vector capacity:
use VecConsumer;
let consumer = with_capacity; // Pre-allocate for 1000 items
🏗️ Architecture
Vector processing flow:
Vec<T> ──> VecProducer ──> Stream<T> ──> Transformer ──> Stream<T> ──> VecConsumer ──> Vec<T>
Vector Flow:
- VecProducer iterates over vector elements
- Items flow through transformers
- VecConsumer collects items into vector
- Vector size grows dynamically
🔧 Configuration
Producer Configuration
- Error Strategy: Error handling strategy
- Name: Component name for logging
Consumer Configuration
- Capacity: Pre-allocated capacity
- Error Strategy: Error handling strategy
- Name: Component name for logging
🔍 Error Handling
Vector errors are handled through the error system:
use ErrorStrategy;
let producer = new
.with_error_strategy;
⚡ Performance Considerations
- Pre-allocation: Use
with_capacityfor known sizes - Dynamic Growth: Vector grows as needed
- Memory Efficiency: Efficient vector operations
📝 Examples
For more examples, see:
🔗 Dependencies
streamweave-vec depends on:
streamweave- Core traitsstreamweave-error- Error handlingstreamweave-message(optional) - Message envelope supporttokio- Async runtimefutures- Stream utilities
🎯 Use Cases
Vector integration is used for:
- Dynamic Data: Process data with unknown size
- Memory Efficiency: Efficient memory usage
- Testing: Test pipelines with dynamic data
- Data Collection: Collect stream items into vectors
📖 Documentation
🔗 See Also
- streamweave - Core traits
- streamweave-array - Array-based streaming
- streamweave-error - Error handling
🤝 Contributing
Contributions are welcome! Please see the Contributing Guide for details.
📄 License
This project is licensed under the CC BY-SA 4.0 license.