TornaxO7 / RevRead

The counterpart to the `std::io::Read` trait.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RevRead

This crate provides the reversed version of the Read trait with some implementors where it's suitable. You just need to add the prefix rev_ to all functions of Read and you get its reversed version.

Example

use rev_read::RevRead;
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]);

    // The reversed version:
    //                           [--] <- notice the `rev_` here
    assert_eq!(values.as_slice().rev_read(&mut buffer).ok(), Some(1));
    //                 [-] and the buffer contains the value starting from the back!
    assert_eq!(buffer, [3]);
}

About

The counterpart to the `std::io::Read` trait.

License:GNU General Public License v2.0


Languages

Language:Rust 98.3%Language:Nix 1.7%