pub struct Larry {
pub file: File,
/* private fields */
}
Expand description
A Larry
is a “line array”. It allows one to access a file as a
lazily-read array of lines. This allows efficient random access to large
files such as log files.
Fields§
§file: File
Implementations§
Source§impl Larry
impl Larry
Sourcepub fn new(path: &Path) -> Result<Larry, Error>
pub fn new(path: &Path) -> Result<Larry, Error>
Constructs a new Larry
.
Construction requires that the file be scanned for line-terminal byte sequences.
§Examples
use larry::Larry;
use std::path::Path;
let mut larry = Larry::new(Path::new("production.log"))?;
§Errors
Any std::io::Error
arising while opening the file and scanning its contents
for line endings will be returned.
Sourcepub fn get(&mut self, i: usize) -> Result<&str, Lerror>
pub fn get(&mut self, i: usize) -> Result<&str, Lerror>
Obtain a particular line.
§Examples
use larry::Larry;
use std::path::Path;
let mut larry = Larry::new(Path::new("production.log"))?;
// print the last line of the file
let last_line_index = larry.len() - 1;
print!("{}", larry.get(last_line_index)?);
§Errors
Index bound errors if you ask for a line beyond the end of the file and IO errors if the file has changed since the larry was created.
Sourcepub fn offset(&self, i: usize) -> Result<u64, Lerror>
pub fn offset(&self, i: usize) -> Result<u64, Lerror>
Returns the byte offset of line i from the start of the file.
§Examples
use larry::Larry;
use std::path::Path;
let larry = Larry::new(Path::new("production.log"))?;
// print the last line of the file
let last_line_index = larry.len() - 1;
print!("{}", larry.offset(last_line_index)?);
§Errors
Index bound errors if you ask for a line beyond the end of the file
Auto Trait Implementations§
impl Freeze for Larry
impl RefUnwindSafe for Larry
impl Send for Larry
impl Sync for Larry
impl Unpin for Larry
impl UnwindSafe for Larry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more