#io-read #read #adapter #add #implementors #iter #iterator-item-u8

read_iter

To any std::io::Read implementor, add also Iterator<Item=u8> implementation

3 releases

0.1.2 Dec 6, 2020
0.1.1 Dec 6, 2020
0.1.0 Dec 6, 2020

#3 in #implementors

24 downloads per month
Used in nop-json

MIT license

7KB
117 lines

read_iter

Documentation crates.io

To any std::io::Read implementor, add also Iterator<Item=u8> implementation.

Installation

In Cargo.toml of your project add:

[dependencies]
read_iter = "0.1"

Examples

use std::fs::File;
use read_iter::ReadIter;

let file = File::open("/tmp/test.txt").unwrap();
// "file" implements std::io::Read
let mut it = ReadIter::new(file);
// now "it" also implements std::io::Read
// and "&mut it" implements Iterator<Item=u8>
// also "it" has internal buffer, and implements std::io::BufRead
for byte in &mut it
{	// ...
}
// in case of i/o error, the iteration ends, and take_last_error() will return Err
it.take_last_error().unwrap();

lib.rs:

To any std::io::Read implementor, add also Iterator<Item=u8> implementation.

Installation

In Cargo.toml of your project add:

[dependencies]
read_iter = "1.0"

Examples

use std::fs::File;
use read_iter::ReadIter;

let file = File::open("/tmp/test.txt").unwrap();
// "file" implements std::io::Read
let mut it = ReadIter::new(file);
// now "it" also implements std::io::Read
// and "&mut it" implements Iterator<Item=u8>
// also "it" has internal buffer, and implements std::io::BufRead
for byte in &mut it
{	// ...
}
// in case of i/o error, the iteration ends, and take_last_error() will return Err
it.take_last_error().unwrap();

No runtime deps