Created
May 25, 2018 16:54
-
-
Save rust-play/cd30b13d160daf27709a75bae4f56130 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate csv; | |
use std::fs::File; | |
use std::io; | |
pub struct RowIter<'a, T: 'a> { | |
iter: &'a ::csv::StringRecordsIter<'a, T>, | |
} | |
pub struct CsvDataTable<R> { | |
reader: csv::Reader<R>, | |
} | |
impl CsvDataTable<File> { | |
pub fn open_with_table( | |
path: &str, | |
) -> Result<CsvDataTable<File>, ::io::Error> { | |
let csv_file_reader = File::open(path) | |
.expect("failed to open csv file for reading"); | |
let csv_reader = csv::ReaderBuilder::new() | |
.from_reader(csv_file_reader); | |
Ok(CsvDataTable { | |
reader: csv_reader, | |
}) | |
} | |
pub fn rows<'c>(&'c mut self) -> RowIter<'c, File> { | |
RowIter { | |
iter: &self.reader.records(), | |
} | |
} | |
} | |
fn main () {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment