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

no-std countio

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

6 releases

0.2.19 Sep 3, 2024
0.2.18 Jun 26, 2024
0.2.17 Mar 7, 2024
0.2.15 Jul 31, 2023
0.2.3 Mar 13, 2023

#158 in Asynchronous

Download history 1522/week @ 2024-08-17 1625/week @ 2024-08-24 1977/week @ 2024-08-31 1780/week @ 2024-09-07 1335/week @ 2024-09-14 1656/week @ 2024-09-21 1202/week @ 2024-09-28 1667/week @ 2024-10-05 1886/week @ 2024-10-12 2317/week @ 2024-10-19 1837/week @ 2024-10-26 1798/week @ 2024-11-02 1835/week @ 2024-11-09 1819/week @ 2024-11-16 1815/week @ 2024-11-23 1467/week @ 2024-11-30

7,392 downloads per month
Used in 5 crates (2 directly)

MIT license

19KB
385 lines

countio

Build Status Crate Docs Crate Version Crate Coverage

Check out other spire projects here.

The wrapper struct to enable byte counting for std::io::{Read, Write, 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–5.5MB
~19K SLoC