Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A CSV parser for Rust, with Serde support.

License

Unlicense and 2 other licenses found

Licenses found

Unlicense
UNLICENSE
Unknown
COPYING
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

BurntSushi/rust-csv

A fast and flexible CSV reader and writer for Rust, with support for Serde.

Build statuscrates.io

Dual-licensed under MIT or theUNLICENSE.

Documentation

https://docs.rs/csv

If you're new to Rust, thetutorialis a good place to start.

Usage

To bring this crate into your repository, either addcsv to yourCargo.toml, or runcargo add csv.

Example

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

Example with Serde

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

Unlicense
UNLICENSE
Unknown
COPYING
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp