countio 0.2.5

Byte counting for std::io::{Read, Write, Seek} and its async variants from futures and tokio.
Documentation
countio-0.2.5 has been yanked.

countio

Build Status Crate Docs Crate Version Crate Coverage

Also check out other xwde 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};
use countio::Counter;

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

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

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

fn main() {
    let writer = Vec::new();
    let writer = Counter::new(writer);
    let mut writer = BufWriter::new(writer);

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

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

Links