https://github.com/luser/read-byte-slice
A Rust crate for iterating over chunks of bytes as slices
https://github.com/luser/read-byte-slice
Last synced: 11 months ago
JSON representation
A Rust crate for iterating over chunks of bytes as slices
- Host: GitHub
- URL: https://github.com/luser/read-byte-slice
- Owner: luser
- License: apache-2.0
- Created: 2017-09-01T17:43:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-06T16:17:34.000Z (over 4 years ago)
- Last Synced: 2025-04-10T16:12:47.383Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[](https://travis-ci.org/luser/read-byte-slice) [](https://crates.io/crates/read-byte-slice) [](https://docs.rs/read-byte-slice)
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.)
# Example
```rust
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();
}
```
# License
`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.
[`chunks`]: https://doc.rust-lang.org/std/primitive.slice.html#method.chunks
[`FallibleStreamingIterator`]: https://docs.rs/fallible-streaming-iterator/*/fallible_streaming_iterator/trait.FallibleStreamingIterator.html