streamweave-stdio
Standard I/O integration for StreamWeave
Read from stdin and write to stdout/stderr with StreamWeave pipelines.
The streamweave-stdio package provides producers and consumers for integrating StreamWeave with POSIX standard streams (stdin, stdout, stderr). It enables building command-line tools and interactive pipelines that process data from standard input and output results to standard output or error streams.
✨ Key Features
- StdinProducer: Read lines from standard input
- StdoutConsumer: Write items to standard output
- StderrConsumer: Write items to standard error
- Line-by-Line Processing: Process input line by line
- Interactive Pipelines: Build interactive command-line tools
📦 Installation
Add this to your Cargo.toml:
[]
= "0.3.0"
🚀 Quick Start
Basic Pipeline
use ;
use PipelineBuilder;
let pipeline = new
.producer
.transformer
.consumer;
pipeline.run.await?;
Reading from Stdin
use StdinProducer;
let producer = new;
// Reads lines from stdin and produces them as String items
Writing to Stdout
use StdoutConsumer;
let consumer = new;
// Writes items to stdout
Writing to Stderr
use StderrConsumer;
let consumer = new;
// Writes items to stderr (for error output)
📖 API Overview
StdinProducer
Reads lines from standard input:
Key Methods:
new()- Create new stdin producerproduce()- Generate stream from stdin
StdoutConsumer
Writes items to standard output:
Key Methods:
new()- Create new stdout consumerconsume(stream)- Write stream items to stdout
StderrConsumer
Writes items to standard error:
Key Methods:
new()- Create new stderr consumerconsume(stream)- Write stream items to stderr
📚 Usage Examples
Simple Echo Pipeline
Echo input to output:
use ;
use PipelineBuilder;
let pipeline = new
.producer
.consumer;
pipeline.run.await?;
Transform and Output
Transform input before outputting:
use ;
use PipelineBuilder;
use MapTransformer;
let pipeline = new
.producer
.transformer
.consumer;
pipeline.run.await?;
Error Output
Write errors to stderr:
use ;
use PipelineBuilder;
let pipeline = new
.producer
.transformer
.consumer;
pipeline.run.await?;
Interactive Processing
Process input interactively:
use ;
use PipelineBuilder;
// Process input as it arrives
let pipeline = new
.producer
.transformer
.consumer;
// Run interactively
pipeline.run.await?;
🏗️ Architecture
Standard I/O integration:
┌──────────┐
│ stdin │───> StdinProducer ───> Stream ───> Transformer ───> Stream ───> StdoutConsumer ───> stdout
└──────────┘ └──────────┘
┌──────────┐
│ stderr │
└──────────┘
I/O Flow:
- StdinProducer reads lines from stdin
- Lines flow through transformers
- StdoutConsumer writes to stdout
- StderrConsumer writes to stderr (for errors)
🔧 Configuration
Producer Configuration
Configure stdin producer:
let producer = new
.with_config;
Consumer Configuration
Configure stdout/stderr consumers:
let consumer = new
.with_config;
🔍 Error Handling
Standard I/O errors are handled through the error system:
use ErrorStrategy;
let pipeline = new
.with_error_strategy
.producer
.consumer;
⚡ Performance Considerations
- Line Buffering: Input is read line by line
- Streaming: Output is streamed, not buffered
- Interactive: Suitable for interactive use
- Memory Efficient: Processes one line at a time
📝 Examples
For more examples, see:
🔗 Dependencies
streamweave-stdio depends on:
streamweave- Core traitsstreamweave-error- Error handlingstreamweave-message(optional) - Message envelope supporttokio- Async runtimefutures- Stream utilitiesasync-stream- Stream generation
🎯 Use Cases
Standard I/O is used for:
- Command-Line Tools: Build CLI tools that process stdin/stdout
- Interactive Pipelines: Process data interactively
- Unix Pipelines: Integrate with Unix pipe operations
- Text Processing: Process text streams line by line
- Error Handling: Separate normal output from error output
📖 Documentation
🔗 See Also
- streamweave - Core traits
- streamweave-file - File I/O
- streamweave-pipeline - Pipeline API
🤝 Contributing
Contributions are welcome! Please see the Contributing Guide for details.
📄 License
This project is licensed under the CC BY-SA 4.0 license.