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

no-std countio

Byte counting for std::io::{Read, Write, Seek} and its async variants from futures and tokio

4 releases

0.2.17 Mar 7, 2024
0.2.15 Jul 31, 2023
0.2.3 Mar 13, 2023

#208 in Asynchronous

Download history 53/week @ 2024-02-04 23/week @ 2024-02-11 27/week @ 2024-02-18 140/week @ 2024-02-25 362/week @ 2024-03-03 115/week @ 2024-03-10 30/week @ 2024-03-17 12/week @ 2024-03-24 177/week @ 2024-03-31 61/week @ 2024-04-07 109/week @ 2024-04-14 76/week @ 2024-04-21 1410/week @ 2024-04-28 2077/week @ 2024-05-05

3,681 downloads per month
Used in sitemapo

MIT license

18KB
374 lines

countio

Build Status Crate Docs Crate Version Crate Coverage

Also check out other spire-rs projects here.

The wrapper struct to enable byte counting for std::io::Read, std::io::Write, std::io::Seek and its asynchronous variants from futures and tokio crates.

Features

  • std to enable std::io::{Read, Write, Seek}. Enabled by default.
  • futures to enable futures_io::{AsyncRead, AsyncWrite, AsyncSeek}.
  • tokio to enable tokio::io::{AsyncRead, AsyncWrite, AsyncSeek}.

Examples

  • 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(())
}

Other crates

Dependencies

~0–1.1MB
~19K SLoC