Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
benches/ | 03-May-2024 | - | 527 | 492 | ||
examples/ | 03-May-2024 | - | 141,508 | 141,223 | ||
src/ | 03-May-2024 | - | 12,203 | 5,010 | ||
tests/ | 03-May-2024 | - | 512 | 435 | ||
.cargo_vcs_info.json | D | 03-May-2024 | 94 | 6 | 6 | |
.gitignore | D | 03-May-2024 | 88 | 10 | 9 | |
Android.bp | D | 03-May-2024 | 1.9 KiB | 61 | 57 | |
COPYING | D | 03-May-2024 | 126 | 4 | 2 | |
Cargo.toml | D | 03-May-2024 | 1.4 KiB | 74 | 63 | |
Cargo.toml.orig | D | 03-May-2024 | 960 | 39 | 32 | |
ISSUE_TEMPLATE.md | D | 03-May-2024 | 1.3 KiB | 38 | 23 | |
LICENSE | D | 03-May-2024 | 2.2 KiB | 48 | 37 | |
LICENSE-MIT | D | 03-May-2024 | 1.1 KiB | 22 | 17 | |
METADATA | D | 03-May-2024 | 596 | 24 | 22 | |
MODULE_LICENSE_MIT | D | 03-May-2024 | 0 | |||
OWNERS | D | 03-May-2024 | 40 | 2 | 1 | |
README.md | D | 03-May-2024 | 2.5 KiB | 111 | 84 | |
TEST_MAPPING | D | 03-May-2024 | 337 | 18 | 17 | |
UNLICENSE | D | 03-May-2024 | 1.2 KiB | 25 | 20 | |
cargo2android.json | D | 03-May-2024 | 35 | 4 | 4 | |
rustfmt.toml | D | 03-May-2024 | 44 | 3 | 2 |
README.md
1csv 2=== 3A fast and flexible CSV reader and writer for Rust, with support for Serde. 4 5[](https://github.com/BurntSushi/csv/actions) 6[](https://crates.io/crates/csv) 7 8Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org). 9 10 11### Documentation 12 13https://docs.rs/csv 14 15If you're new to Rust, the 16[tutorial](https://docs.rs/csv/1.0.0/csv/tutorial/index.html) 17is a good place to start. 18 19 20### Usage 21 22Add this to your `Cargo.toml`: 23 24```toml 25[dependencies] 26csv = "1.2" 27``` 28 29### Example 30 31This example shows how to read CSV data from stdin and print each record to 32stdout. 33 34There are more examples in the 35[cookbook](https://docs.rs/csv/1.0.0/csv/cookbook/index.html). 36 37```rust 38use std::{error::Error, io, process}; 39 40fn example() -> Result<(), Box<dyn Error>> { 41 // Build the CSV reader and iterate over each record. 42 let mut rdr = csv::Reader::from_reader(io::stdin()); 43 for result in rdr.records() { 44 // The iterator yields Result<StringRecord, Error>, so we check the 45 // error here. 46 let record = result?; 47 println!("{:?}", record); 48 } 49 Ok(()) 50} 51 52fn main() { 53 if let Err(err) = example() { 54 println!("error running example: {}", err); 55 process::exit(1); 56 } 57} 58``` 59 60The above example can be run like so: 61 62```text 63$ git clone git://github.com/BurntSushi/rust-csv 64$ cd rust-csv 65$ cargo run --example cookbook-read-basic < examples/data/smallpop.csv 66``` 67 68### Example with Serde 69 70This example shows how to read CSV data from stdin into your own custom struct. 71By default, the member names of the struct are matched with the values in the 72header record of your CSV data. 73 74```rust 75use std::{error::Error, io, process}; 76 77#[derive(Debug, serde::Deserialize)] 78struct Record { 79 city: String, 80 region: String, 81 country: String, 82 population: Option<u64>, 83} 84 85fn example() -> Result<(), Box<dyn Error>> { 86 let mut rdr = csv::Reader::from_reader(io::stdin()); 87 for result in rdr.deserialize() { 88 // Notice that we need to provide a type hint for automatic 89 // deserialization. 90 let record: Record = result?; 91 println!("{:?}", record); 92 } 93 Ok(()) 94} 95 96fn main() { 97 if let Err(err) = example() { 98 println!("error running example: {}", err); 99 process::exit(1); 100 } 101} 102``` 103 104The above example can be run like so: 105 106```text 107$ git clone git://github.com/BurntSushi/rust-csv 108$ cd rust-csv 109$ cargo run --example cookbook-read-serde < examples/data/smallpop.csv 110``` 111