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

tee_readwrite

为 duplicating reads/writes 到 std::io::{Read,Write} 类型提供简单的 TeeReader/TeeWriter 类型

2 个不稳定版本

0.2.0 2023 年 8 月 16 日
0.1.0 2019 年 7 月 30 日

#661Rust 模式

Download history 129/week @ 2024-03-13 146/week @ 2024-03-20 112/week @ 2024-03-27 129/week @ 2024-04-03 120/week @ 2024-04-10 148/week @ 2024-04-17 66/week @ 2024-04-24 65/week @ 2024-05-01 583/week @ 2024-05-08 197/week @ 2024-05-15 808/week @ 2024-05-22 160/week @ 2024-05-29 766/week @ 2024-06-05 629/week @ 2024-06-12 655/week @ 2024-06-19 726/week @ 2024-06-26

2,786 每月下载量
2 crates 中使用

0BSD 许可证

7KB
74

tee_readwrite

tee_readwrite

此模块允许您将读取/写入镜像到另一个读取/写入(如 POSIX tee)

示例

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]);

许可证:0BSD

无运行时依赖