Inspired by Python's csv
module, a very basic csv reader & writer.
The primary use-case of this library is interacting with unstructured, variably structured, or dubiously structured data. As such, you probably want the far more robust and far better implemented csv
crate.
Goals:
* Provide a String
-based mechanism to read and write CSV files in rfc4180
format.
* Handle mixed formats resiliently, such as mismatched and newlines within quotes.
Non-Goals:
* Any interpretation of the contents of the CSV structure itself - everything is an owned String
* serde
support - if you need it, go use the csv
crate.
fn iterexample() -> Result<(), CSVError> {
let mut input = iroxcsv::CSVReader::new(std::io::stdin());
loop {
// iterate over each line of the input
let line : Option
fn mapexample() -> Result<(), CSVError> {
let mut maps = iroxcsv::CSVMapReader::new(std::io::stdin());
loop {
// iterate over each line of the input
let mayberow : Option
Writing a CSV File using Maps:
```rust
fn mapwriterexample() -> Result<(), CSVError> {
let mut buf: Vec
let mut map = BTreeMap::new(); map.insert("first".tostring(), "firstColFirstRowVal".tostring()); map.insert("second".tostring(), "secondColFirstRowVal".tostring()); map.insert("third".tostring(), "thirdColFirstRowVal".tostring()); writer.write_fields(&map)?;
map.clear(); map.insert("first".tostring(), "firstColSecondRowVal".tostring()); map.insert("second".tostring(), "secondColSecondRowVal".tostring()); map.insert("third".tostring(), "thirdColSecondRowVal".tostring()); writer.write_fields(&map)?;
Ok(())
}
will result in a buffer:
csv
first,second,third
firstColFirstRowVal,secondColFirstRowVal,thirdColFirstRowVal
firstColSecondRowVal,secondColSecondRowVal,thirdColSecondRowVal
```