#io-read #buffer #reverse #reader #buf-reader

read_collection

A collection of different variants of the std::io::Read trait

2 releases

0.0.2 Jun 12, 2024
0.0.1 Jun 12, 2024

#748 in Parser implementations

Download history 206/week @ 2024-06-07 46/week @ 2024-06-14

252 downloads per month

Custom license

66KB
1K SLoC

Read Collection

This crate provides some other variants of the Read trait, like ReadBack or RevRead.

Example (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]);

    // With `ReadBack`:
    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]);
}

Status

Implemented:

  • ReadBack for reading back duh
    • ReadBack trait
    • BufReadBack trait
      • for &[u8]
      • for Empty
      • BufReadBacker struct
  • RevRead for reading reversed
    • RevRead trait
    • BufRevRead trait
      • for &[u8]
      • for Empty
      • BufRevReader struct

Dependencies

~170–315KB