[][src]Struct tabfile::Tabfile

pub struct Tabfile { /* fields omitted */ }

A read-only open handle for a tab-separated file.

To make use of this struct, put it into a for-loop:

extern crate tabfile;
use tabfile::Tabfile;

// setup for `file` ellided

let tabfile = Tabfile::open(file.path()).unwrap();
for line_result in tabfile {
    match line_result {
        Ok(line) => { // line is a tabfile::Record object
            let fields = line.fields();
            println!("{}", fields[0]); // print values in first column
            let line_string = line.line(); //get the original line
            println!("complete line={}", line_string);
        },
        Err(io_error) => eprintln!("{}", io_error) // std::io::Error
    }
}

Tabfile supports the builder pattern. You can configure the Tabfile before using it in a for loop like so:

// setup for `file` ellided

let tabfile = Tabfile::open(file.path())
    .unwrap() // trust your hard disk and file system
    .separator(',') // if you have comma-separated values
    .comment_character('#') // if you want to ignore lines starting with #
    .skip_lines(2); // if you know that the first 2 lines are not relevant to you

Once you have gotten familiar with Tabfile, you probably want to check out Record.

Implementations

impl Tabfile[src]

pub fn open<P: AsRef<Path>>(path: P) -> Result<Tabfile, Error>[src]

Open an existing tab file

pub fn separator(self, sep: char) -> Self[src]

Set the separator of the tab file reader.

The default is '\t'

pub fn skip_lines(self, num_lines: usize) -> Self[src]

Set the number of lines that should be skipped when reading the tab file.

The default is 0.

pub fn comment_character(self, comment_character: char) -> Self[src]

Set a comment character for lines that should be ignored.

All lines starting with the comment character will be ignored. By default there is no comment character. If you use this method in combination with skip_lines note that skip_lines is always checked first and the first n lines will be dropped regardless of whether they have a comment character at the beginning or not.

pub fn skip_empty_lines(self, skip: bool) -> Self[src]

Skip empty lines.

If set to true (which is the default) then the iterator will only yield non-empty vectors. If you combine this with the skip method, then the first n lines will always be skipped regardless of whether or not they are empty.

Trait Implementations

impl IntoIterator for Tabfile[src]

type Item = Result<Record, Error>

The type of the elements being iterated over.

type IntoIter = RowIterator

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl RefUnwindSafe for Tabfile

impl Send for Tabfile

impl Sync for Tabfile

impl Unpin for Tabfile

impl UnwindSafe for Tabfile

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.