Skip to content

Commit

Permalink
*: fix all warnings and update code
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Feb 14, 2023
1 parent b9479c2 commit ea0273c
Show file tree
Hide file tree
Showing 36 changed files with 96 additions and 221 deletions.
4 changes: 1 addition & 3 deletions examples/cookbook-read-basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn example() -> Result<(), Box<dyn Error>> {
// Build the CSV reader and iterate over each record.
Expand Down
4 changes: 1 addition & 3 deletions examples/cookbook-read-colon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn example() -> Result<(), Box<dyn Error>> {
let mut rdr =
Expand Down
4 changes: 1 addition & 3 deletions examples/cookbook-read-no-headers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn example() -> Result<(), Box<dyn Error>> {
let mut rdr =
Expand Down
5 changes: 2 additions & 3 deletions examples/cookbook-read-serde.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

use serde::Deserialize;

Expand Down
4 changes: 1 addition & 3 deletions examples/cookbook-write-basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn example() -> Result<(), Box<dyn Error>> {
let mut wtr = csv::Writer::from_writer(io::stdout());
Expand Down
4 changes: 1 addition & 3 deletions examples/cookbook-write-serde.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

use serde::Serialize;

Expand Down
3 changes: 1 addition & 2 deletions examples/tutorial-error-02.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io;
use std::process;
use std::{io, process};

fn main() {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-error-03.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn main() {
if let Err(err) = run() {
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-error-04.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn main() {
if let Err(err) = run() {
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-perf-alloc-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<u64, Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-perf-alloc-02.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<u64, Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-perf-alloc-03.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<u64, Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial-perf-serde-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

use serde::Deserialize;

Expand Down
6 changes: 2 additions & 4 deletions examples/tutorial-perf-serde-02.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::error::Error;
use std::io;
use std::process;

#![allow(dead_code)]
use serde::Deserialize;
use std::{error::Error, io, process};

#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial-perf-serde-03.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

use serde::Deserialize;

Expand Down
5 changes: 1 addition & 4 deletions examples/tutorial-pipeline-pop-01.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::env;
use std::error::Error;
use std::io;
use std::process;
use std::{env, error::Error, io, process};

use serde::{Deserialize, Serialize};

Expand Down
5 changes: 1 addition & 4 deletions examples/tutorial-pipeline-search-01.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::env;
use std::error::Error;
use std::io;
use std::process;
use std::{env, error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
// Get the query from the positional arguments.
Expand Down
5 changes: 1 addition & 4 deletions examples/tutorial-pipeline-search-02.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::env;
use std::error::Error;
use std::io;
use std::process;
use std::{env, error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let query = match env::args().nth(1) {
Expand Down
6 changes: 1 addition & 5 deletions examples/tutorial-read-01.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::env;
use std::error::Error;
use std::ffi::OsString;
use std::fs::File;
use std::process;
use std::{env, error::Error, ffi::OsString, fs::File, process};

fn run() -> Result<(), Box<dyn Error>> {
let file_path = get_first_arg()?;
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-delimiter-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-headers-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut rdr =
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-headers-02.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-serde-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-serde-02.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

// This introduces a type alias so that we can conveniently reference our
// record type.
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-read-serde-03.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::collections::HashMap;
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

// This introduces a type alias so that we can conveniently reference our
// record type.
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial-read-serde-04.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

// This lets us write `#[derive(Deserialize)]`.
use serde::Deserialize;
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial-read-serde-invalid-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

use serde::Deserialize;

Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial-read-serde-invalid-02.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::error::Error;
use std::io;
use std::process;
#![allow(dead_code)]
use std::{error::Error, io, process};

use serde::Deserialize;
#[derive(Debug, Deserialize)]
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-write-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut wtr = csv::Writer::from_writer(io::stdout());
Expand Down
5 changes: 1 addition & 4 deletions examples/tutorial-write-02.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::env;
use std::error::Error;
use std::ffi::OsString;
use std::process;
use std::{env, error::Error, ffi::OsString, process};

fn run() -> Result<(), Box<dyn Error>> {
let file_path = get_first_arg()?;
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-write-delimiter-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut wtr = csv::WriterBuilder::new()
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-write-serde-01.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

fn run() -> Result<(), Box<dyn Error>> {
let mut wtr = csv::Writer::from_writer(io::stdout());
Expand Down
4 changes: 1 addition & 3 deletions examples/tutorial-write-serde-02.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};

use serde::Serialize;

Expand Down
25 changes: 7 additions & 18 deletions src/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ stdout.
```no_run
# //cookbook-read-basic.rs
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};
fn example() -> Result<(), Box<dyn Error>> {
// Build the CSV reader and iterate over each record.
Expand Down Expand Up @@ -74,9 +72,8 @@ method.
```no_run
# //cookbook-read-serde.rs
use std::error::Error;
use std::io;
use std::process;
# #![allow(dead_code)]
use std::{error::Error, io, process};
use serde::Deserialize;
Expand Down Expand Up @@ -124,9 +121,7 @@ by `:` instead of `,`.
```no_run
# //cookbook-read-colon.rs
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};
fn example() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
Expand Down Expand Up @@ -164,9 +159,7 @@ first record is not skipped. This example shows how to disable that setting.
```no_run
# //cookbook-read-no-headers.rs
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};
fn example() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
Expand Down Expand Up @@ -201,9 +194,7 @@ This example shows how to write CSV data to stdout.
```no_run
# //cookbook-write-basic.rs
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};
fn example() -> Result<(), Box<dyn Error>> {
let mut wtr = csv::Writer::from_writer(io::stdout());
Expand Down Expand Up @@ -241,9 +232,7 @@ headers are written automatically.
```no_run
# //cookbook-write-serde.rs
use std::error::Error;
use std::io;
use std::process;
use std::{error::Error, io, process};
use serde::Serialize;
Expand Down
16 changes: 5 additions & 11 deletions src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn deserialize_string_record<'de, D: Deserialize<'de>>(
D::deserialize(&mut deser).map_err(|err| {
Error::new(ErrorKind::Deserialize {
pos: record.position().map(Clone::clone),
err: err,
err,
})
})
}
Expand All @@ -47,7 +47,7 @@ pub fn deserialize_byte_record<'de, D: Deserialize<'de>>(
D::deserialize(&mut deser).map_err(|err| {
Error::new(ErrorKind::Deserialize {
pos: record.position().map(Clone::clone),
err: err,
err,
})
})
}
Expand Down Expand Up @@ -197,10 +197,7 @@ impl<'r> DeRecord<'r> for DeStringRecord<'r> {
}

fn error(&self, kind: DeserializeErrorKind) -> DeserializeError {
DeserializeError {
field: Some(self.field.saturating_sub(1)),
kind: kind,
}
DeserializeError { field: Some(self.field.saturating_sub(1)), kind }
}

fn infer_deserialize<'de, V: Visitor<'de>>(
Expand Down Expand Up @@ -291,10 +288,7 @@ impl<'r> DeRecord<'r> for DeByteRecord<'r> {
}

fn error(&self, kind: DeserializeErrorKind) -> DeserializeError {
DeserializeError {
field: Some(self.field.saturating_sub(1)),
kind: kind,
}
DeserializeError { field: Some(self.field.saturating_sub(1)), kind }
}

fn infer_deserialize<'de, V: Visitor<'de>>(
Expand Down Expand Up @@ -913,7 +907,7 @@ mod tests {
struct Foo;

#[derive(Deserialize, Debug, PartialEq)]
struct Bar {};
struct Bar {}

let got = de_headers::<Foo>(&[], &[]);
assert_eq!(got.unwrap(), Foo);
Expand Down

0 comments on commit ea0273c

Please sign in to comment.