aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-01 19:26:23 +0100
committerJeff Vander Stoep <jeffv@google.com>2024-02-01 19:26:24 +0100
commit54f5cc4cdf0edbdd2a4398e0c1b71e743c00eb20 (patch)
tree309bdc33842825215ebab815894e14d3e21dc6a1
parent80d82cf8216be6f06edfcd96a7c32485fed7be2a (diff)
downloadcsv-54f5cc4cdf0edbdd2a4398e0c1b71e743c00eb20.tar.gz
Upgrade csv to 1.3.0
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/rust/crates/csv For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: Ie92db86c8689b9c276defb2929870e852dd289a3
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml11
-rw-r--r--Cargo.toml.orig7
-rw-r--r--METADATA23
-rw-r--r--README.md15
-rw-r--r--src/error.rs9
-rw-r--r--src/lib.rs16
-rw-r--r--src/tutorial.rs6
-rw-r--r--src/writer.rs42
10 files changed, 84 insertions, 49 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 727eb00..5133d5b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "fa01b78533a58d6c1087990a79a42c97c6edd069"
+ "sha1": "6374614ef8240d110626409ae882339b8145282c"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 239737e..765ccba 100644
--- a/Android.bp
+++ b/Android.bp
@@ -42,7 +42,7 @@ rust_library {
host_supported: true,
crate_name: "csv",
cargo_env_compat: true,
- cargo_pkg_version: "1.2.0",
+ cargo_pkg_version: "1.3.0",
srcs: ["src/lib.rs"],
edition: "2021",
rustlibs: [
diff --git a/Cargo.toml b/Cargo.toml
index 56e3597..d8705a6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@
[package]
edition = "2021"
-rust-version = "1.60"
+rust-version = "1.61"
name = "csv"
-version = "1.2.0"
+version = "1.3.0"
authors = ["Andrew Gallant <jamslam@gmail.com>"]
exclude = [
"/.github",
@@ -37,19 +37,18 @@ categories = [
]
license = "Unlicense/MIT"
repository = "https://github.com/BurntSushi/rust-csv"
-resolver = "2"
[profile.bench]
-debug = true
+debug = 2
[profile.release]
-debug = true
+debug = 2
[lib]
bench = false
[dependencies.csv-core]
-version = "0.1.10"
+version = "0.1.11"
[dependencies.itoa]
version = "1"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 0f60210..c3f7482 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "csv"
-version = "1.2.0" #:version
+version = "1.3.0" #:version
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "Fast CSV parsing with support for serde."
documentation = "https://docs.rs/csv"
@@ -12,8 +12,7 @@ license = "Unlicense/MIT"
categories = ["encoding", "parser-implementations"]
exclude = ["/.github", "/ci/*", "/scripts/*"]
edition = "2021"
-resolver = "2"
-rust-version = "1.60"
+rust-version = "1.61"
[workspace]
members = ["csv-core", "csv-index"]
@@ -22,7 +21,7 @@ members = ["csv-core", "csv-index"]
bench = false
[dependencies]
-csv-core = { path = "csv-core", version = "0.1.10" }
+csv-core = { path = "csv-core", version = "0.1.11" }
itoa = "1"
ryu = "1"
serde = "1.0.55"
diff --git a/METADATA b/METADATA
index 9bef55d..9540efd 100644
--- a/METADATA
+++ b/METADATA
@@ -1,23 +1,20 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/csv
-# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+# Usage: tools/external_updater/updater.sh update external/rust/crates/csv
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "csv"
description: "Fast CSV parsing with support for serde."
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/csv"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/csv/csv-1.2.0.crate"
- }
- version: "1.2.0"
license_type: NOTICE
last_upgrade_date {
- year: 2023
+ year: 2024
month: 2
- day: 15
+ day: 1
+ }
+ homepage: "https://crates.io/crates/csv"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/csv/csv-1.3.0.crate"
+ version: "1.3.0"
}
}
diff --git a/README.md b/README.md
index 83f3ea0..938928f 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ csv
===
A fast and flexible CSV reader and writer for Rust, with support for Serde.
-[![Build status](https://github.com/BurntSushi/csv/workflows/ci/badge.svg)](https://github.com/BurntSushi/csv/actions)
+[![Build status](https://github.com/BurntSushi/rust-csv/workflows/ci/badge.svg)](https://github.com/BurntSushi/rust-csv/actions)
[![crates.io](https://img.shields.io/crates/v/csv.svg)](https://crates.io/crates/csv)
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
@@ -13,18 +13,15 @@ Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
https://docs.rs/csv
If you're new to Rust, the
-[tutorial](https://docs.rs/csv/1.0.0/csv/tutorial/index.html)
+[tutorial](https://docs.rs/csv/1.*/csv/tutorial/index.html)
is a good place to start.
### Usage
-Add this to your `Cargo.toml`:
+To bring this crate into your repository, either add `csv` to your
+`Cargo.toml`, or run `cargo add csv`.
-```toml
-[dependencies]
-csv = "1.2"
-```
### Example
@@ -32,7 +29,7 @@ This example shows how to read CSV data from stdin and print each record to
stdout.
There are more examples in the
-[cookbook](https://docs.rs/csv/1.0.0/csv/cookbook/index.html).
+[cookbook](https://docs.rs/csv/1.*/csv/cookbook/index.html).
```rust
use std::{error::Error, io, process};
@@ -103,7 +100,7 @@ fn main() {
The above example can be run like so:
-```text
+```
$ git clone git://github.com/BurntSushi/rust-csv
$ cd rust-csv
$ cargo run --example cookbook-read-serde < examples/data/smallpop.csv
diff --git a/src/error.rs b/src/error.rs
index ae2a6d8..1dfe304 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -312,6 +312,15 @@ impl<W> IntoInnerError<W> {
&self.err
}
+ /// Consumes the [`IntoInnerError`] and returns the error which caused the
+ /// call to [`Writer::into_inner`](crate::Writer::into_inner) to fail.
+ ///
+ /// Unlike [`IntoInnerError::error`], this can be used to obtain ownership
+ /// of the underlying error.
+ pub fn into_error(self) -> io::Error {
+ self.err
+ }
+
/// Returns the underlying writer which generated the error.
///
/// The returned value can be used for error recovery, such as
diff --git a/src/lib.rs b/src/lib.rs
index eb7fe5f..314fc36 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,20 +42,12 @@ position information, configuration knobs or iterator types.
# Setup
-Add this to your `Cargo.toml`:
-
-```toml
-[dependencies]
-csv = "1.1"
-```
+Run `cargo add csv` to add the latest version of the `csv` crate to your
+Cargo.toml.
If you want to use Serde's custom derive functionality on your custom structs,
-then add this to your `[dependencies]` section of `Cargo.toml`:
-
-```toml
-[dependencies]
-serde = { version = "1", features = ["derive"] }
-```
+then run `cargo add serde --features derive` to add the `serde` crate with its
+`derive` feature enabled to your `Cargo.toml`.
# Example
diff --git a/src/tutorial.rs b/src/tutorial.rs
index 7bce7c0..8b96c09 100644
--- a/src/tutorial.rs
+++ b/src/tutorial.rs
@@ -213,9 +213,9 @@ header1,header2
foo,bar
quux,baz,foobar
$ ./target/debug/csvtutor < invalid
-StringRecord { position: Some(Position { byte: 16, line: 2, record: 1 }), fields: ["foo", "bar"] }
-thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnequalLengths { pos: Some(Position { byte: 24, line: 3, record: 2 }), expected_len: 2, len: 3 }', /checkout/src/libcore/result.rs:859
-note: Run with `RUST_BACKTRACE=1` for a backtrace.
+StringRecord(["foo", "bar"])
+thread 'main' panicked at 'a CSV record: Error(UnequalLengths { pos: Some(Position { byte: 24, line: 3, record: 2 }), expected_len: 2, len: 3 })', src/main.rs:13:29
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
What happened here? First and foremost, we should talk about why the CSV data
diff --git a/src/writer.rs b/src/writer.rs
index 42c85c1..9fef1f1 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -470,6 +470,34 @@ impl WriterBuilder {
self
}
+ /// The comment character that will be used when later reading the file.
+ ///
+ /// If `quote_style` is set to `QuoteStyle::Necessary`, a field will
+ /// be quoted if the comment character is detected anywhere in the field.
+ ///
+ /// The default value is None.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use std::error::Error;
+ /// use csv::WriterBuilder;
+ ///
+ /// # fn main() { example().unwrap(); }
+ /// fn example() -> Result<(), Box<dyn Error>> {
+ /// let mut wtr =
+ /// WriterBuilder::new().comment(Some(b'#')).from_writer(Vec::new());
+ /// wtr.write_record(&["# comment", "another"]).unwrap();
+ /// let buf = wtr.into_inner().unwrap();
+ /// assert_eq!(String::from_utf8(buf).unwrap(), "\"# comment\",another\n");
+ /// Ok(())
+ /// }
+ /// ```
+ pub fn comment(&mut self, comment: Option<u8>) -> &mut WriterBuilder {
+ self.builder.comment(comment);
+ self
+ }
+
/// Set the capacity (in bytes) of the internal buffer used in the CSV
/// writer. This defaults to a reasonable setting.
pub fn buffer_capacity(&mut self, capacity: usize) -> &mut WriterBuilder {
@@ -1068,6 +1096,11 @@ impl<W: io::Write> Writer<W> {
Ok(())
}
+ /// Return a reference to the underlying writer.
+ pub fn get_ref(&self) -> &W {
+ self.wtr.as_ref().unwrap()
+ }
+
/// Flush the contents of the internal buffer and return the underlying
/// writer.
pub fn into_inner(
@@ -1409,4 +1442,13 @@ mod tests {
wtr.serialize((true, 1.3, "hi")).unwrap();
assert_eq!(wtr_as_string(wtr), "true,1.3,hi\n");
}
+
+ #[test]
+ fn comment_char_is_automatically_quoted() {
+ let mut wtr =
+ WriterBuilder::new().comment(Some(b'#')).from_writer(Vec::new());
+ wtr.write_record(&["# comment", "another"]).unwrap();
+ let buf = wtr.into_inner().unwrap();
+ assert_eq!(String::from_utf8(buf).unwrap(), "\"# comment\",another\n");
+ }
}