Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork230
A CSV parser for Rust, with Serde support.
License
Unlicense and 2 other licenses found
Licenses found
BurntSushi/rust-csv
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A fast and flexible CSV reader and writer for Rust, with support for Serde.
Dual-licensed under MIT or theUNLICENSE.
If you're new to Rust, thetutorialis a good place to start.
To bring this crate into your repository, either addcsv
to yourCargo.toml
, or runcargo add csv
.
This example shows how to read CSV data from stdin and print each record tostdout.
There are more examples in thecookbook.
use std::{error::Error, io, process};fnexample() ->Result<(),Box<dynError>>{// Build the CSV reader and iterate over each record.letmut rdr = csv::Reader::from_reader(io::stdin());for resultin rdr.records(){// The iterator yields Result<StringRecord, Error>, so we check the// error here.let record = result?;println!("{:?}", record);}Ok(())}fnmain(){ifletErr(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 theheader record of your CSV data.
use std::{error::Error, io, process};#[derive(Debug, serde::Deserialize)]structRecord{city:String,region:String,country:String,population:Option<u64>,}fnexample() ->Result<(),Box<dynError>>{letmut rdr = csv::Reader::from_reader(io::stdin());for resultin rdr.deserialize(){// Notice that we need to provide a type hint for automatic// deserialization.let record:Record = result?;println!("{:?}", record);}Ok(())}fnmain(){ifletErr(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
About
A CSV parser for Rust, with Serde support.
Topics
Resources
License
Unlicense and 2 other licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.