Struct Tabfile

Source
pub struct Tabfile { /* private fields */ }
Expand description

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§

Source§

impl Tabfile

Source

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

Open an existing tab file

Source

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

Set the separator of the tab file reader.

The default is '\t'

Source

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

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

The default is 0.

Source

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

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.

Source

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

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§

Source§

impl IntoIterator for Tabfile

Source§

type Item = Result<Record, Error>

The type of the elements being iterated over.
Source§

type IntoIter = RowIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.