countio

Crates.iocountio
lib.rscountio
version0.2.19
sourcesrc
created_at2023-02-27 03:13:19.96555
updated_at2024-09-03 07:14:38.380895
descriptionByte counting for std::io::{Read, Write, Seek} and its async variants from futures and tokio.
homepagehttps://github.com/spire-rs/countio
repositoryhttps://github.com/spire-rs/countio
max_upload_size
id795648
size21,703
Oleh Martsokha (martsokha)

documentation

https://docs.rs/countio

README

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

Commit count: 0

cargo fmt