1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! 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.
pub use read_until;
pub use ;