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
impl Tabfile
Sourcepub fn separator(self, sep: char) -> Self
pub fn separator(self, sep: char) -> Self
Set the separator of the tab file reader.
The default is '\t'
Sourcepub fn skip_lines(self, num_lines: usize) -> Self
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
.
Sourcepub fn comment_character(self, comment_character: char) -> Self
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.
Sourcepub fn skip_empty_lines(self, skip: bool) -> Self
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.