commit | e00a8b118af958f1a9851aef7a5e261082cb9c00 | [log] [tgz] |
---|---|---|
author | Wei Li <[email protected]> | Wed Jul 31 16:18:50 2024 -0700 |
committer | Wei Li <[email protected]> | Wed Jul 31 16:18:50 2024 -0700 |
tree | 0b6bcc34bfc75acef8b0769b2043dd6fe05aa9a5 | |
parent | e0f4ddb420cd52d69c39e84ec02a837e99538464 [diff] |
Cleanup license metadata in external/rust/crates/csv. File LICENSE contains copies of LICENSE-MIT and UNLICENSE and is added in Android codebase, so change it to symlink that points to file LICENSE-MIT and use it in Android.bp. Bug: 346390141 Test: CIs Change-Id: I65fe9e40e0d3c90a3c48abdc47d14fc6dbbb4df4
A fast and flexible CSV reader and writer for Rust, with support for Serde.
Dual-licensed under MIT or the UNLICENSE.
If you're new to Rust, the tutorial is a good place to start.
To bring this crate into your repository, either add csv
to your Cargo.toml
, or run cargo add csv
.
This example shows how to read CSV data from stdin and print each record to stdout.
There are more examples in the cookbook.
use std::{error::Error, io, process}; fn example() -> Result<(), Box<dyn Error>> { // Build the CSV reader and iterate over each record. let mut rdr = csv::Reader::from_reader(io::stdin()); for result in rdr.records() { // The iterator yields Result<StringRecord, Error>, so we check the // error here. let record = result?; println!("{:?}", record); } Ok(()) } fn main() { if let Err(err) = example() { println!("error running example: {}", err); process::exit(1); } }
The above example can be run like so:
$ git clone git://github.com/BurntSushi/rust-csv $ cd rust-csv $ cargo run --example cookbook-read-basic < examples/data/smallpop.csv
This example shows how to read CSV data from stdin into your own custom struct. By default, the member names of the struct are matched with the values in the header record of your CSV data.
use std::{error::Error, io, process}; #[derive(Debug, serde::Deserialize)] struct Record { city: String, region: String, country: String, population: Option<u64>, } fn example() -> Result<(), Box<dyn Error>> { let mut rdr = csv::Reader::from_reader(io::stdin()); for result in rdr.deserialize() { // Notice that we need to provide a type hint for automatic // deserialization. let record: Record = result?; println!("{:?}", record); } Ok(()) } fn main() { if let Err(err) = example() { println!("error running example: {}", err); process::exit(1); } }
The above example can be run like so:
$ git clone git://github.com/BurntSushi/rust-csv $ cd rust-csv $ cargo run --example cookbook-read-serde < examples/data/smallpop.csv