leftover 0.0.2

A BufRead adapter for data spanning buffer boundaries
Documentation
//! Buffered reading with support for data that spans chunks.
//!
//! [`LeftoverReader`] wraps a [`BufRead`](std::io::BufRead) reader and provides
//! [`fill_view`](LeftoverReader::fill_view) to access saved bytes alongside the
//! current chunk. If more input is needed, [`accumulate`](LeftoverView::accumulate)
//! copies the whole chunk into the leftover for the next read.
//!
//! A [`LeftoverView`] lets you inspect, take, or discard these bytes.
//!
//! # Example
//!
//! Collect newline-delimited records, keeping the delimiters. A small buffer
//! makes records span chunks; `take_owned` copies each record into a new vector
//! so it can be kept after the next read.
//!
//! ```rust
//! use std::io::BufReader;
//!
//! use leftover::LeftoverReader;
//!
//! let input = BufReader::with_capacity(3, b"one\n\nlast".as_slice());
//! let mut reader = LeftoverReader::new(input);
//! let mut records = Vec::new();
//!
//! loop {
//!     let view = reader.fill_view()?;
//!     if view.buffer().is_empty() {
//!         // Keep the final record even if it has no newline.
//!         if !view.leftover().is_empty() {
//!             records.push(view.take_owned(0));
//!         }
//!         break;
//!     }
//!     if let Some(end) = view.buffer().iter().position(|&byte| byte == b'\n') {
//!         // Include the newline in the record.
//!         records.push(view.take_owned(end + 1));
//!     } else {
//!         // Save this part and continue with the next chunk.
//!         view.accumulate();
//!     }
//! }
//!
//! assert_eq!(records, [b"one\n".as_slice(), b"\n", b"last"]);
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! Use [`take_view`](LeftoverView::take_view) when you can finish processing the
//! data before filling the next view.
//! [`consume`](LeftoverView::consume) discards data without copying it.

mod read_until;
mod reader;

pub use self::read_until::read_until;
pub use self::reader::{LeftoverReader, LeftoverView};