#reader-writer #tee #io-write #mirror #posix #another #tee-reader

tee_readwrite

Simple TeeReader/TeeWriter types for duplicating reads/writes to std::io::{Read,Write} types

2 unstable releases

0.2.0 Aug 16, 2023
0.1.0 Jul 30, 2019

#33 in #tee

Download history 90/week @ 2024-11-29 228/week @ 2024-12-06 274/week @ 2024-12-13 106/week @ 2024-12-20 324/week @ 2024-12-27 109/week @ 2025-01-03 109/week @ 2025-01-10 250/week @ 2025-01-17 164/week @ 2025-01-24 157/week @ 2025-01-31 230/week @ 2025-02-07 258/week @ 2025-02-14 158/week @ 2025-02-21 218/week @ 2025-02-28 506/week @ 2025-03-07 182/week @ 2025-03-14

1,087 downloads per month
Used in 2 crates

0BSD license

7KB
74 lines

tee_readwrite

tee_readwrite

This module allows you to mirror read/writes to another read/write (like POSIX tee)

Examples

TeeReader

use tee_readwrite::{TeeReader, TeeWriter};
// make a new reader
let reader = std::io::Cursor::new(vec![1,2,3]);
let mut tee = TeeReader::new(
    reader,
    vec![], // vec implements write
    false   // we don't care about flushing here
);

// read all of the elements from the cursor into this vec
// each 'read' call will be written to the wrapped writer
let mut results = vec![];
assert_eq!(tee.read_to_end(&mut results).expect("read"), 3);

// consume the tee, returning the reader and the mirroring writer
let (_read, output) = tee.into_inner();
assert_eq!(results, output);

TeeWriter

use tee_readwrite::{TeeReader, TeeWriter};
let writer = vec![];
let mut tee = TeeWriter::new(writer, vec![]);
for i in 1..=3 {
    let _ = tee.write_all(&[i]);
}
// we can borrow the output writer
assert_eq!(tee.borrow_output(), &[1,2,3]);

// consume the tee, returning the writer and its tee output
let (left, output) = tee.into_inner();
assert_eq!(left, output);
assert_eq!(output, &[1,2,3]);

License: 0BSD

No runtime deps