[][src]Struct larry::Larry

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

Methods

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<String, String>
[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, String>
[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 Send for Larry

impl Sync for Larry

Blanket Implementations

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

impl<T> From for T
[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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