Skip to main content

async_rev_buf/
lib.rs

1//! # Async Reverse Buffer Reader
2//!
3//! A high-performance async buffered reader for reading lines in reverse order.
4//! Optimized for processing log files, chat histories, or any text data where
5//! you need to read from the end backwards.
6//!
7//! ## Features
8//!
9//! - **High Performance**: 8+ million lines/sec throughput
10//! - **Streaming Interface**: Clean `lines().next_line().await` pattern
11//! - **Memory Efficient**: Fixed buffer size, minimal allocations
12//! - **Unicode Support**: Proper UTF-8 handling
13//! - **Async/Await**: Full tokio compatibility
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! use async_rev_buf::RevBufReader;
19//! use tokio::fs::File;
20//!
21//! #[tokio::main]
22//! async fn main() -> std::io::Result<()> {
23//!     let file = File::open("large.log").await?;
24//!     let reader = RevBufReader::new(file);
25//!     let mut lines = reader.lines();
26//!
27//!     // Read last 10 lines efficiently
28//!     for _ in 0..10 {
29//!         if let Some(line) = lines.next_line().await? {
30//!             println!("{}", line);
31//!         } else {
32//!             break;
33//!         }
34//!     }
35//!
36//!     Ok(())
37//! }
38//! ```
39//!
40//! ## API Patterns
41//!
42//! ### Streaming Interface (Recommended)
43//!
44//! ```rust
45//! # use async_rev_buf::RevBufReader;
46//! # use std::io::Cursor;
47//! # async fn example() -> std::io::Result<()> {
48//! let reader = RevBufReader::new(Cursor::new("line1\nline2\nline3"));
49//! let mut lines = reader.lines();
50//!
51//! while let Some(line) = lines.next_line().await? {
52//!     println!("{}", line);
53//! }
54//! # Ok(()) }
55//! ```
56//!
57//! ### Direct Method Access
58//!
59//! ```rust
60//! # use async_rev_buf::RevBufReader;
61//! # use std::io::Cursor;
62//! # async fn example() -> std::io::Result<()> {
63//! let mut reader = RevBufReader::new(Cursor::new("line1\nline2\nline3"));
64//!
65//! while let Some(line) = reader.next_line().await? {
66//!     println!("{}", line);
67//! }
68//! # Ok(()) }
69//! ```
70
71mod buf_reader;
72mod lines;
73
74pub use buf_reader::RevBufReader;
75pub use lines::Lines;
76
77/// Default buffer size: 8 KB
78pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;