Trait ConcatRead

Source
pub trait ConcatRead: Read {
    type Item;

    // Required methods
    fn skip(&mut self) -> bool;
    fn current(&self) -> Option<&Self::Item>;
}
Expand description

A special Read trait for concatenated readers.

This traids adds special function to fetch the current Read item and to skip to the next item.

Required Associated Types§

Required Methods§

Source

fn skip(&mut self) -> bool

Skips to the next Read item in the internal Iterator.

use concat_reader::concat;
use std::io::{self, Read};
use crate::concat_reader::ConcatRead;

fn main() -> io::Result<()> {
    let value1 = "some string".as_bytes();
    let value2 = "another string".as_bytes();

    let mut buffer = [0; 4];
    let mut f = concat(vec![value1, value2]);
    f.read_exact(&mut buffer)?;
    assert_eq!(buffer, "some".as_bytes());

    //skip to the next Read object
    f.skip();
    f.read_exact(&mut buffer)?;
    assert_eq!(buffer, "anot".as_bytes());
    Ok(())
}
Source

fn current(&self) -> Option<&Self::Item>

Returns the current Read item in the internal iterator being read from.

Implementors§