Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply select clippy recommendations #257

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.33.0"
4 changes: 2 additions & 2 deletions csv-core/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ enum NfaState {
}

/// A list of NFA states that have an explicit representation in the DFA.
const NFA_STATES: &'static [NfaState] = &[
const NFA_STATES: &[NfaState] = &[
NfaState::StartRecord,
NfaState::StartField,
NfaState::EndFieldDelim,
Expand Down Expand Up @@ -1238,7 +1238,7 @@ impl DfaClasses {
panic!("added too many classes")
}
self.classes[b as usize] = self.next_class as u8;
self.next_class = self.next_class + 1;
self.next_class += 1;
}

fn num_classes(&self) -> usize {
Expand Down
10 changes: 4 additions & 6 deletions csv-core/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl WriterBuilder {
escape: b'\\',
double_quote: true,
};
WriterBuilder { wtr: wtr }
WriterBuilder { wtr }
}

/// Builder a CSV writer from this configuration.
Expand Down Expand Up @@ -171,12 +171,10 @@ pub struct Writer {
impl Clone for Writer {
fn clone(&self) -> Writer {
let mut requires_quotes = [false; 256];
for i in 0..256 {
requires_quotes[i] = self.requires_quotes[i];
}
requires_quotes[..256].clone_from_slice(&self.requires_quotes[..256]);
Writer {
state: self.state.clone(),
requires_quotes: requires_quotes,
requires_quotes,
delimiter: self.delimiter,
term: self.term,
style: self.style,
Expand Down Expand Up @@ -497,7 +495,7 @@ pub fn is_non_numeric(input: &[u8]) -> bool {
// I suppose this could be faster if we wrote validators of numbers instead
// of using the actual parser, but that's probably a lot of work for a bit
// of a niche feature.
!s.parse::<f64>().is_ok() && !s.parse::<i128>().is_ok()
s.parse::<f64>().is_err() && s.parse::<i128>().is_err()
}

/// Escape quotes `input` and writes the result to `output`.
Expand Down
3 changes: 1 addition & 2 deletions csv-index/src/simple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io;

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use csv;

/// A simple index for random access to CSV records.
///
Expand Down Expand Up @@ -153,7 +152,7 @@ impl<R: io::Read + io::Seek> RandomAccessSimple<R> {
pub fn open(mut rdr: R) -> csv::Result<RandomAccessSimple<R>> {
rdr.seek(io::SeekFrom::End(-8))?;
let len = rdr.read_u64::<BigEndian>()?;
Ok(RandomAccessSimple { rdr: rdr, len: len })
Ok(RandomAccessSimple { rdr, len })
}

/// Get the position of the record at index `i`.
Expand Down
4 changes: 2 additions & 2 deletions src/byte_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl Bounds {
None => 0,
Some(&start) => start,
};
Some(ops::Range { start: start, end: end })
Some(ops::Range { start, end })
}

/// Returns a slice of ending positions of all fields.
Expand All @@ -695,7 +695,7 @@ impl Bounds {
/// If there are no fields, this returns `0`.
#[inline]
fn end(&self) -> usize {
self.ends().last().map(|&i| i).unwrap_or(0)
self.ends().last().copied().unwrap_or(0)
}

/// Returns the number of fields in these bounds.
Expand Down
16 changes: 8 additions & 8 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 @@ -199,7 +199,7 @@ impl<'r> DeRecord<'r> for DeStringRecord<'r> {
fn error(&self, kind: DeserializeErrorKind) -> DeserializeError {
DeserializeError {
field: Some(self.field.saturating_sub(1)),
kind: kind,
kind,
}
}

Expand Down Expand Up @@ -287,13 +287,13 @@ impl<'r> DeRecord<'r> for DeByteRecord<'r> {

#[inline]
fn peek_field(&mut self) -> Option<&'r [u8]> {
self.it.peek().map(|s| *s)
self.it.peek().copied()
}

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

Expand Down Expand Up @@ -335,8 +335,8 @@ macro_rules! deserialize_int {
visitor: V,
) -> Result<V::Value, Self::Error> {
let field = self.next_field()?;
let num = if field.starts_with("0x") {
<$inttype>::from_str_radix(&field[2..], 16)
let num = if let Some(stripped) = field.strip_prefix("0x") {
<$inttype>::from_str_radix(stripped, 16)
} else {
field.parse()
};
Expand Down Expand Up @@ -913,7 +913,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
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub struct FromUtf8Error {
impl FromUtf8Error {
/// Create a new FromUtf8Error.
pub(crate) fn new(rec: ByteRecord, err: Utf8Error) -> FromUtf8Error {
FromUtf8Error { record: rec, err: err }
FromUtf8Error { record: rec, err }
}

/// Access the underlying `ByteRecord` that failed UTF-8 validation.
Expand Down Expand Up @@ -271,7 +271,7 @@ pub struct Utf8Error {

/// Create a new UTF-8 error.
pub fn new_utf8_error(field: usize, valid_up_to: usize) -> Utf8Error {
Utf8Error { field: field, valid_up_to: valid_up_to }
Utf8Error { field, valid_up_to }
}

impl Utf8Error {
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<W> IntoInnerError<W> {
/// (This is a visibility hack. It's public in this module, but not in the
/// crate.)
pub(crate) fn new(wtr: W, err: io::Error) -> IntoInnerError<W> {
IntoInnerError { wtr: wtr, err: err }
IntoInnerError { wtr, err }
}

/// Returns the error which caused the call to `into_inner` to fail.
Expand Down
16 changes: 8 additions & 8 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1927,9 +1927,9 @@ impl<R: io::Read, D: DeserializeOwned> DeserializeRecordsIntoIter<R, D> {
rdr.headers().ok().map(Clone::clone)
};
DeserializeRecordsIntoIter {
rdr: rdr,
rdr,
rec: StringRecord::new(),
headers: headers,
headers,
_priv: PhantomData,
}
}
Expand Down Expand Up @@ -1985,9 +1985,9 @@ impl<'r, R: io::Read, D: DeserializeOwned> DeserializeRecordsIter<'r, R, D> {
rdr.headers().ok().map(Clone::clone)
};
DeserializeRecordsIter {
rdr: rdr,
rdr,
rec: StringRecord::new(),
headers: headers,
headers,
_priv: PhantomData,
}
}
Expand Down Expand Up @@ -2025,7 +2025,7 @@ pub struct StringRecordsIntoIter<R> {

impl<R: io::Read> StringRecordsIntoIter<R> {
fn new(rdr: Reader<R>) -> StringRecordsIntoIter<R> {
StringRecordsIntoIter { rdr: rdr, rec: StringRecord::new() }
StringRecordsIntoIter { rdr, rec: StringRecord::new() }
}

/// Return a reference to the underlying CSV reader.
Expand Down Expand Up @@ -2067,7 +2067,7 @@ pub struct StringRecordsIter<'r, R: 'r> {

impl<'r, R: io::Read> StringRecordsIter<'r, R> {
fn new(rdr: &'r mut Reader<R>) -> StringRecordsIter<'r, R> {
StringRecordsIter { rdr: rdr, rec: StringRecord::new() }
StringRecordsIter { rdr, rec: StringRecord::new() }
}

/// Return a reference to the underlying CSV reader.
Expand Down Expand Up @@ -2101,7 +2101,7 @@ pub struct ByteRecordsIntoIter<R> {

impl<R: io::Read> ByteRecordsIntoIter<R> {
fn new(rdr: Reader<R>) -> ByteRecordsIntoIter<R> {
ByteRecordsIntoIter { rdr: rdr, rec: ByteRecord::new() }
ByteRecordsIntoIter { rdr, rec: ByteRecord::new() }
}

/// Return a reference to the underlying CSV reader.
Expand Down Expand Up @@ -2143,7 +2143,7 @@ pub struct ByteRecordsIter<'r, R: 'r> {

impl<'r, R: io::Read> ByteRecordsIter<'r, R> {
fn new(rdr: &'r mut Reader<R>) -> ByteRecordsIter<'r, R> {
ByteRecordsIter { rdr: rdr, rec: ByteRecord::new() }
ByteRecordsIter { rdr, rec: ByteRecord::new() }
}

/// Return a reference to the underlying CSV reader.
Expand Down
6 changes: 2 additions & 4 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::fmt;
use std::io;
use std::mem;

use itoa;
use ryu;
use serde::ser::{
Error as SerdeError, Serialize, SerializeMap, SerializeSeq,
SerializeStruct, SerializeStructVariant, SerializeTuple,
Expand All @@ -20,7 +18,7 @@ pub fn serialize<S: Serialize, W: io::Write>(
wtr: &mut Writer<W>,
value: S,
) -> Result<(), Error> {
value.serialize(&mut SeRecord { wtr: wtr })
value.serialize(&mut SeRecord { wtr })
}

struct SeRecord<'w, W: 'w + io::Write> {
Expand Down Expand Up @@ -452,7 +450,7 @@ struct SeHeader<'w, W: 'w + io::Write> {

impl<'w, W: io::Write> SeHeader<'w, W> {
fn new(wtr: &'w mut Writer<W>) -> Self {
SeHeader { wtr: wtr, state: HeaderState::Write }
SeHeader { wtr, state: HeaderState::Write }
}

fn wrote_header(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/string_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl StringRecord {
match (read_res, utf8_res) {
(Err(err), _) => Err(err),
(Ok(_), Err(err)) => {
Err(Error::new(ErrorKind::Utf8 { pos: Some(pos), err: err }))
Err(Error::new(ErrorKind::Utf8 { pos: Some(pos), err }))
}
(Ok(eof), Ok(())) => Ok(eof),
}
Expand Down