| Crates.io | read-byte-slice |
| lib.rs | read-byte-slice |
| version | 0.1.2 |
| created_at | 2017-09-01 17:53:15.776438+00 |
| updated_at | 2017-12-08 11:39:36.120358+00 |
| description | An iterator over chunks of bytes as slices from an underlying reader. |
| homepage | https://github.com/luser/read-byte-slice |
| repository | https://github.com/luser/read-byte-slice |
| max_upload_size | |
| id | 30181 |
| size | 20,397 |
This crate implements a type ByteSliceIter that reads bytes from a reader and allows iterating
over them as slices with a maximum length, similar to the chunks method on slices.
It is implemented as a FallibleStreamingIterator so that it can reuse its buffer and not
allocate for each chunk. (That trait is re-exported here for convenience.)
extern crate read_byte_slice;
use read_byte_slice::{ByteSliceIter, FallibleStreamingIterator};
use std::io;
fn work() -> io::Result<()> {
let bytes = b"0123456789abcdef0123456789abcdef";
// Iterate over the bytes in 8-byte chunks.
let mut iter = ByteSliceIter::new(&bytes[..], 8);
while let Some(chunk) = iter.next()? {
println!("{:?}", chunk);
}
Ok(())
}
fn main() {
work().unwrap();
}
read-byte-slice is distributed under the terms of both the MIT license and
the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.