#io-write

written_size

Implementation of std::io::Write which calculates how much data is written into it

1 unstable release

Uses old Rust 2015

0.1.0 May 14, 2016

#61 in #io-write

WTFPL license

4KB

Written Size

Implementation of std::io::Write which calculates how much data was written into it.

Installation

Add the following to your Cargo.toml:

[dependencies]
written_size = "0.1"

API docs

Api documentation can be found here.

Example

use std::io::Write;
use written_size::WrittenSize;

let mut ws = WrittenSize::new();
ws.write(&[1, 2, 3]).unwrap();
ws.write(&[1, 2, 3]).unwrap();

assert!(ws.size() == 6);

lib.rs:

This crate provides a way to calculate how much data is being written into std::io::Write. This is mostly useful if you want to know how much space is necessary to serialize something without actually allocating that space or writing data anywhere.

Example usage:

use std::io::Write;
use written_size::WrittenSize;

let mut ws = WrittenSize::new();
ws.write(&[1, 2, 3]).unwrap();
ws.write(&[1, 2, 3]).unwrap();

assert!(ws.size() == 6);

If you want to write data to some other Write instance and at the same time calculating number of bytes written you can use this crate together with the broadcast crate.

If you want to calculate number of bytes read from some Read instance you can use this crate together with the tee crate.

No runtime deps