Function csv_perusal::open_csv

source ·
pub fn open_csv(path: &str) -> Result<Vec<Vec<CSVType>>, CSVPerusalError>
Expand description

Input the file path to a CSV file you want parsed and it will return a two-dimensional vector of CSVType.

§Example

use csv_perusal::{open_csv, CSVType};

fn main() {
    let path = "test_data/MOCK_DATA.csv";
    let data = open_csv(path).unwrap();
 
    data.iter().for_each(|row| {
       row.iter().for_each(|cell| {
           match cell {
               CSVType::Int(val) => print!("INT:{:?},", val),
               CSVType::Float(val) => print!("FLOAT:{:?},", val),
               CSVType::String(val) => print!("STRING:{:?},", val),
               CSVType::Date(val) => print!("DATE:{:?},", val),
               CSVType::Time(val) => print!("TIME:{:?},", val),
               CSVType::DateTime(val) => print!("DATETIME:{:?},", val),
               CSVType::Error(err) => print!("ERROR:{:?},", err),
               CSVType::Empty => print!("NONE,"),
           }
       });
       print!("\n");
    );
}