Struct larry::Larry [−][src]
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
impl Larry
[src]
pub fn new(path: &Path) -> Result<Larry, Error>
[src]
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.
pub fn get(&mut self, i: usize) -> Result<&str, Lerror>
[src]
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.
pub fn offset(&self, i: usize) -> Result<u64, Lerror>
[src]
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
pub fn len(&self) -> usize
[src]
Returns number of lines.
Examples
use larry::Larry; use std::path::Path; let mut larry = Larry::new(Path::new("production.log"))?; println!("number of lines line: {}", larry.len());
Auto Trait Implementations
impl RefUnwindSafe for Larry
impl Send for Larry
impl Sync for Larry
impl Unpin for Larry
impl UnwindSafe for Larry
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,