#read-write #io-read #async-io #byte #future #tokio #io-write

无std countio

为std::io::{Read, Write, Seek}及其来自futures和tokio的异步变体提供字节计数

5个版本

0.2.18 2024年6月26日
0.2.17 2024年3月7日
0.2.15 2023年7月31日
0.2.3 2023年3月13日

#159异步

Download history 1372/week @ 2024-04-27 2124/week @ 2024-05-04 1941/week @ 2024-05-11 1978/week @ 2024-05-18 2013/week @ 2024-05-25 2131/week @ 2024-06-01 1727/week @ 2024-06-08 1877/week @ 2024-06-15 2117/week @ 2024-06-22 1544/week @ 2024-06-29 1834/week @ 2024-07-06 2042/week @ 2024-07-13 1810/week @ 2024-07-20 2299/week @ 2024-07-27 1653/week @ 2024-08-03 1862/week @ 2024-08-10

7,974 每月下载量
用于 sitemapo

MIT 许可证

19KB
385

countio

Build Status Crate Docs Crate Version Crate Coverage

查看其他 spire 项目 这里.

包装结构体,用于启用对std::io::{Read, Write, Seek}及其来自futurestokio crate的异步变体的字节计数。

功能

  • std启用std::io::{Read, Write, Seek}默认启用
  • futures启用futures_io::{AsyncRead, AsyncWrite, AsyncSeek}
  • tokio启用tokio::io::{AsyncRead, AsyncWrite, AsyncSeek}

示例

  • std::io::Read:
use std::io::{BufRead, BufReader, Result};
use countio::Counter;

fn main() -> Result<()> {
    let reader = "Hello World!".as_bytes();
    let reader = BufReader::new(reader);
    let mut reader = Counter::new(reader);

    let mut buf = String::new();
    let len = reader.read_line(&mut buf)?;

    assert_eq!(len, reader.reader_bytes());
    Ok(())
}
  • std::io::Write:
use std::io::{BufWriter, Write, Result};
use countio::Counter;

fn main() -> Result<()> {
    let writer = Vec::new();
    let writer = BufWriter::new(writer);
    let mut writer = Counter::new(writer);

    let buf = "Hello World!".as_bytes();
    let len = writer.write(buf)?;
    writer.flush()?;

    assert_eq!(len, writer.writer_bytes());
    Ok(())
}

其他crate

依赖项

~0–1.1MB
~19K SLoC