Struct larry::Larry[][src]

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.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.