Crate read_collection
source ·Expand description
This crate provides a collection of different variations of std::io::Read. At the moment, there’s only ReadBack. Feel free to suggest other possible std::io::Read variants which could be added to this collection.
You’ll likely want to use one of the following traits):
§Example with ReadBack
use read_collection::ReadBack;
use std::io::Read;
fn main() {
let values = [1, 2, 3];
let mut buffer = [0];
// How it could look like with `Read`:
assert_eq!(values.as_slice().read(&mut buffer).ok(), Some(1));
assert_eq!(buffer, [1]);
println!("With Read: buffer = [{}]", buffer[0]);
// The read-back version:
assert_eq!(values.as_slice().read_back(&mut buffer).ok(), Some(1));
// [-] and the buffer contains the value starting from the back!
assert_eq!(buffer, [3]);
println!("With ReadBack: buffer = [{}]", buffer[0]);
}Output:
With Read: buffer = [1]
With ReadBack: buffer = [3]
Structs§
- The
BufReadBacker<R>struct adds buffering to anyReadBacker. - An iterator over
u8values of a read-back reader. - Adapter to chain together two
ReadBacks. - An iterator over the contents of an instance of
BufReadBacksplit on a particular byte.
Traits§
- A
BufReadBackis a type ofReadBacker which has an internal buffer, allowing it to perform extra ways of reading. - A trait to read back the content which has been read with the methods of std::io::Read.