Skip to content

Commit 8313603

Browse files
authored
Merge branch 'BurntSushi:master' into master
2 parents 32d3649 + 4a3997e commit 8313603

22 files changed

+201
-269
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "csv"
3-
version = "1.3.1" #:version
3+
version = "1.4.0" #:version
44
authors = ["Andrew Gallant <[email protected]>"]
55
description = "Fast CSV parsing with support for serde."
66
documentation = "https://docs.rs/csv"
@@ -24,11 +24,11 @@ bench = false
2424
csv-core = { path = "csv-core", version = "0.1.11" }
2525
itoa = "1"
2626
ryu = "1"
27-
serde = "1.0.55"
27+
serde_core = "1.0.221"
2828

2929
[dev-dependencies]
3030
bstr = { version = "1.7.0", default-features = false, features = ["alloc", "serde"] }
31-
serde = { version = "1.0.55", features = ["derive"] }
31+
serde = { version = "1.0.221", features = ["derive"] }
3232

3333
[profile.release]
3434
debug = true

benches/bench.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use csv::{
1212
WriterBuilder,
1313
};
1414

15-
static NFL: &'static str = include_str!("../examples/data/bench/nfl.csv");
16-
static GAME: &'static str = include_str!("../examples/data/bench/game.csv");
17-
static POP: &'static str =
18-
include_str!("../examples/data/bench/worldcitiespop.csv");
19-
static MBTA: &'static str =
15+
static NFL: &str = include_str!("../examples/data/bench/nfl.csv");
16+
static GAME: &str = include_str!("../examples/data/bench/game.csv");
17+
static POP: &str = include_str!("../examples/data/bench/worldcitiespop.csv");
18+
static MBTA: &str =
2019
include_str!("../examples/data/bench/gtfs-mbta-stop-times.csv");
2120

2221
#[derive(Debug, Serialize, Deserialize, PartialEq)]

csv-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "csv-core"
3-
version = "0.1.12" #:version
3+
version = "0.1.13" #:version
44
authors = ["Andrew Gallant <[email protected]>"]
55
description = "Bare bones CSV parsing with no_std support."
66
documentation = "https://docs.rs/csv-core"

csv-core/src/reader.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,16 +608,14 @@ impl Reader {
608608
/// this method will fail to strip off the BOM if only part of the BOM is
609609
/// buffered. Hopefully that won't happen very often.
610610
fn strip_utf8_bom<'a>(&self, input: &'a [u8]) -> (&'a [u8], usize) {
611-
let (input, nin) = if {
612-
!self.has_read
613-
&& input.len() >= 3
614-
&& &input[0..3] == b"\xef\xbb\xbf"
615-
} {
611+
if !self.has_read
612+
&& input.len() >= 3
613+
&& &input[0..3] == b"\xef\xbb\xbf"
614+
{
616615
(&input[3..], 3)
617616
} else {
618617
(input, 0)
619-
};
620-
(input, nin)
618+
}
621619
}
622620

623621
#[inline(always)]

examples/cookbook-write-basic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ fn example() -> Result<(), Box<dyn Error>> {
55

66
// When writing records without Serde, the header record is written just
77
// like any other record.
8-
wtr.write_record(&["city", "region", "country", "population"])?;
9-
wtr.write_record(&["Southborough", "MA", "United States", "9686"])?;
10-
wtr.write_record(&["Northbridge", "MA", "United States", "14061"])?;
8+
wtr.write_record(["city", "region", "country", "population"])?;
9+
wtr.write_record(["Southborough", "MA", "United States", "9686"])?;
10+
wtr.write_record(["Northbridge", "MA", "United States", "14061"])?;
1111
wtr.flush()?;
1212
Ok(())
1313
}

examples/tutorial-pipeline-pop-01.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ fn run() -> Result<(), Box<dyn Error>> {
3535
// indicate which type we want to deserialize our record into.
3636
let record: Record = result?;
3737

38-
// `map_or` is a combinator on `Option`. It take two parameters:
39-
// a value to use when the `Option` is `None` (i.e., the record has
40-
// no population count) and a closure that returns another value of
41-
// the same type when the `Option` is `Some`. In this case, we test it
42-
// against our minimum population count that we got from the command
43-
// line.
44-
if record.population.map_or(false, |pop| pop >= minimum_pop) {
38+
// `is_some_and` is a combinator on `Option`. It takes a closure that
39+
// returns `bool` when the `Option` is `Some`. When the `Option` is
40+
// `None`, `false` is always returned. In this case, we test it against
41+
// our minimum population count that we got from the command line.
42+
if record.population.is_some_and(|pop| pop >= minimum_pop) {
4543
wtr.serialize(record)?;
4644
}
4745
}

examples/tutorial-pipeline-search-01.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn run() -> Result<(), Box<dyn Error>> {
1919
// `query` to `wtr`.
2020
for result in rdr.records() {
2121
let record = result?;
22-
if record.iter().any(|field| field == &query) {
22+
if record.iter().any(|field| field == query) {
2323
wtr.write_record(&record)?;
2424
}
2525
}

examples/tutorial-read-headers-02.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ use std::{error::Error, io, process};
22

33
fn run() -> Result<(), Box<dyn Error>> {
44
let mut rdr = csv::Reader::from_reader(io::stdin());
5-
{
6-
// We nest this call in its own scope because of lifetimes.
7-
let headers = rdr.headers()?;
8-
println!("{:?}", headers);
9-
}
5+
let headers = rdr.headers()?;
6+
println!("{:?}", headers);
107
for result in rdr.records() {
118
let record = result?;
129
println!("{:?}", record);
1310
}
14-
// We can ask for the headers at any time. There's no need to nest this
15-
// call in its own scope because we never try to borrow the reader again.
11+
// We can ask for the headers at any time.
1612
let headers = rdr.headers()?;
1713
println!("{:?}", headers);
1814
Ok(())

examples/tutorial-write-01.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ fn run() -> Result<(), Box<dyn Error>> {
55
// Since we're writing records manually, we must explicitly write our
66
// header record. A header record is written the same way that other
77
// records are written.
8-
wtr.write_record(&[
8+
wtr.write_record([
99
"City",
1010
"State",
1111
"Population",
1212
"Latitude",
1313
"Longitude",
1414
])?;
15-
wtr.write_record(&[
15+
wtr.write_record([
1616
"Davidsons Landing",
1717
"AK",
1818
"",
1919
"65.2419444",
2020
"-165.2716667",
2121
])?;
22-
wtr.write_record(&["Kenai", "AK", "7610", "60.5544444", "-151.2583333"])?;
23-
wtr.write_record(&["Oakman", "AL", "", "33.7133333", "-87.3886111"])?;
22+
wtr.write_record(["Kenai", "AK", "7610", "60.5544444", "-151.2583333"])?;
23+
wtr.write_record(["Oakman", "AL", "", "33.7133333", "-87.3886111"])?;
2424

2525
// A CSV writer maintains an internal buffer, so it's important
2626
// to flush the buffer when you're done.

examples/tutorial-write-02.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ fn run() -> Result<(), Box<dyn Error>> {
44
let file_path = get_first_arg()?;
55
let mut wtr = csv::Writer::from_path(file_path)?;
66

7-
wtr.write_record(&[
7+
wtr.write_record([
88
"City",
99
"State",
1010
"Population",
1111
"Latitude",
1212
"Longitude",
1313
])?;
14-
wtr.write_record(&[
14+
wtr.write_record([
1515
"Davidsons Landing",
1616
"AK",
1717
"",
1818
"65.2419444",
1919
"-165.2716667",
2020
])?;
21-
wtr.write_record(&["Kenai", "AK", "7610", "60.5544444", "-151.2583333"])?;
22-
wtr.write_record(&["Oakman", "AL", "", "33.7133333", "-87.3886111"])?;
21+
wtr.write_record(["Kenai", "AK", "7610", "60.5544444", "-151.2583333"])?;
22+
wtr.write_record(["Oakman", "AL", "", "33.7133333", "-87.3886111"])?;
2323

2424
wtr.flush()?;
2525
Ok(())

0 commit comments

Comments
 (0)