pub struct Larry {
pub file: File,
// some fields omitted
}
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.
Constructs a new Larry
.
Construction requires that the file be scanned for line-terminal byte
sequences.
use larry::Larry;
use std::path::Path;
let mut larry = Larry::new(Path::new("production.log"))?;
Any std::io::Error
arising while opening the file and scanning its contents
for line endings will be returned.
Obtain a particular line.
use larry::Larry;
use std::path::Path;
let mut larry = Larry::new(Path::new("production.log"))?;
let last_line_index = larry.len() - 1;
print!("{}", larry.get(last_line_index)?);
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.
Returns the byte offset of line i from the start of the file.
use larry::Larry;
use std::path::Path;
let larry = Larry::new(Path::new("production.log"))?;
let last_line_index = larry.len() - 1;
print!("{}", larry.offset(last_line_index)?);
Index bound errors if you ask for a line beyond the end of the file
Returns number of lines.
use larry::Larry;
use std::path::Path;
let mut larry = Larry::new(Path::new("production.log"))?;
println!("number of lines line: {}", larry.len());
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more