Expand description
The wrapper struct to enable byte counting for std::io::Read and
std::io::Write and its asynchronous variants from futures
and tokio
crates.
Also check out other xwde
projects here.
Features
std
to enable std::io::Read and std::io::Write. Enabled by default.futures
to enable futures_io::AsyncRead and futures_io::AsyncWrite.tokio
to enable tokio::io::AsyncRead and tokio::io::AsyncWrite.
Examples
std::io::Read
:
use std::io::{BufRead, BufReader};
use countio::Counter;
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).unwrap();
assert_eq!(len, reader.reader_bytes());
std::io::Write
:
use std::io::{BufWriter, Write};
use countio::Counter;
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).unwrap();
writer.flush().unwrap();
assert_eq!(len, writer.writer_bytes());
Structs
- The
Counter<D>
struct adds byte counting to any reader or writer.