Expand description
Permits to load CSV data into a Doc.
Wraps the given CSV data and returns it as Doc. The first line is used as header line which defined the field names. All subsequent lines are imported as entries.
§Examples
CSV into a doc:
let input = "F1;F2;F3\r\nA;X;1\r\nB;Y;2";
let reader = ReaderBuilder::new()
.delimiter(b';')
.has_headers(false)
.from_reader(input.as_bytes());
let doc = csv_to_doc(reader).unwrap();
assert_eq!(doc.root().at(0).query("F1").as_str().unwrap(), "A");
assert_eq!(doc.root().at(0).query("F2").as_str().unwrap(), "X");
assert_eq!(doc.root().at(0).query("F3").as_str().unwrap(), "1");
assert_eq!(doc.root().at(1).query("F1").as_str().unwrap(), "B");
assert_eq!(doc.root().at(1).query("F2").as_str().unwrap(), "Y");
assert_eq!(doc.root().at(1).query("F3").as_str().unwrap(), "2");
Functions§
- Transforms the given CSV data into a doc which is a list of objects.