diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:52:36 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:52:36 +0000 |
commit | 293e0871cb5bb06d100d4696efab7a5adfcaca76 (patch) | |
tree | 309bdc33842825215ebab815894e14d3e21dc6a1 | |
parent | d4716e769e8519b7f5a2cb272db0a20ff6c02f35 (diff) | |
parent | 54f5cc4cdf0edbdd2a4398e0c1b71e743c00eb20 (diff) | |
download | csv-simpleperf-release.tar.gz |
Snap for 11400057 from 54f5cc4cdf0edbdd2a4398e0c1b71e743c00eb20 to simpleperf-releasesimpleperf-release
Change-Id: I2793d3756640e135b172391b9d942caa4befa09e
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | Cargo.toml.orig | 7 | ||||
-rw-r--r-- | METADATA | 23 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | src/error.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/tutorial.rs | 6 | ||||
-rw-r--r-- | src/writer.rs | 42 |
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 @@ -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: [ @@ -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" @@ -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" } } @@ -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 @@ -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"); + } } |