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 Dec 4, 2023

#592 in Asynchronous

Download history 16/week @ 2024-09-25 3/week @ 2024-10-02 1/week @ 2024-10-09 135/week @ 2024-10-30 6/week @ 2024-11-06 1/week @ 2024-11-13 1/week @ 2024-11-20 221/week @ 2024-12-11 15/week @ 2024-12-18 133/week @ 2025-01-08

157 downloads per month

MIT license

12KB
272 lines

Crate Info

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