pub fn parse_csv_as_record<T: MValueCompatible>(
source: &str,
delimiter: Option<char>,
line_delimiter: Option<char>,
) -> Vec<T>Expand description
Parse CSV data into a record the source is the source of the CSV data the delimiter is the character used to separate fields the line_delimiter is the character used to separate lines returns an object with key-value pairs whose keys and values are both strings
Example:
use gistools::readers::parse_csv_as_record;
use s2json::MValue;
#[derive(Debug, Default, Clone, PartialEq, MValue)]
struct Test {
a: String,
b: String,
c: String,
}
let source = "a,b,c\n1,2,3\n4,5,6";
let res = parse_csv_as_record::<Test>(source, None, None);
assert_eq!(
res,
vec![
Test { a: "1".into(), b: "2".into(), c: "3".into() },
Test { a: "4".into(), b: "5".into(), c: "6".into() },
]
);