14 releases (4 breaking)
0.5.0 | Jan 12, 2025 |
---|---|
0.4.1 | Dec 14, 2024 |
0.3.0 | Oct 31, 2024 |
0.2.0 | Jul 1, 2024 |
0.1.0 |
|
#592 in Asynchronous
157 downloads per month
12KB
272 lines
Multiple Readers
multiple-readers
is a Rust library aimed at simplifying the process of combining multiple types that implement the std::io::Read trait into a unified reader.
Features
- Combines multiple types that implement the std::io::Read trait into a unified reader.
- Can read from data sources sequentially until all data sources are exhausted.
- Supports tokio (
Unstable
)
Example
use std::io::{Cursor, Read};
use multi_readers::wrap;
fn main() -> std::io::Result<()> {
// Same type
let r1 = Cursor::new("Hello, ");
let r2 = Cursor::new("World!");
let mut readers = wrap!(r1.clone(), r2.clone());
let mut hello_world = String::new();
readers.read_to_string(&mut hello_world)?;
assert_eq!(hello_world.as_str(), "Hello, World!");
// Different types
let r3 = Cursor::new(b" Rust!");
let mut readers = wrap!(dyn Read, r1, r2, r3);
let mut buf = String::new();
readers.read_to_string(&mut buf)?;
assert_eq!(buf.as_str(), "Hello, World! Rust!");
Ok(())
}
Dependencies
~0–5.5MB
~19K SLoC