From 2db331c8be2b06968ee6919c2b37f3c26b077010 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 16 Jun 2020 19:40:52 -0400 Subject: [PATCH] Fix existing clippy lints. Closes #49. --- src/blob.rs | 8 ++++---- src/de.rs | 23 ++++++++++------------- src/ser.rs | 20 +++++++------------- src/value.rs | 8 ++++---- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index d8a9434..8ce6a17 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -35,7 +35,7 @@ use value::Value; /// let mut dst = Vec::new(); /// nbt.to_zlib_writer(&mut dst).unwrap(); /// ``` -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq)] pub struct Blob { title: String, content: HashMap, @@ -76,7 +76,7 @@ impl Blob { let content = Value::from_reader(tag, src)?; match content { Value::Compound(map) => Ok(Blob { - title: title, + title, content: map, }), _ => Err(Error::NoRootCompound), @@ -153,7 +153,7 @@ impl Blob { // inserted into the file. let nvalue = value.into(); if let Value::List(ref vals) = nvalue { - if vals.len() != 0 { + if !vals.is_empty() { let first_id = vals[0].id(); for nbt in vals { if nbt.id() != first_id { @@ -205,7 +205,7 @@ impl fmt::Display for Blob { for (name, tag) in self.content.iter() { write!(f, " {}(\"{}\"): ", tag.tag_name(), name)?; tag.print(f, 2)?; - write!(f, "\n")?; + writeln!(f)?; } write!(f, "}}") } diff --git a/src/de.rs b/src/de.rs index 4803b7f..b10a807 100644 --- a/src/de.rs +++ b/src/de.rs @@ -135,10 +135,7 @@ where R: io::Read, { fn new(outer: &'a mut Decoder) -> Self { - MapDecoder { - outer: outer, - tag: None, - } + MapDecoder { outer, tag: None } } } @@ -175,7 +172,7 @@ impl<'de: 'a, 'a, R: io::Read + 'a> de::MapAccess<'de> for MapDecoder<'a, R> { let mut de = match self.tag { Some(tag) => InnerDecoder { outer: self.outer, - tag: tag, + tag, }, None => unimplemented!(), }; @@ -199,9 +196,9 @@ where let tag = raw::read_bare_byte(&mut outer.reader)?; let length = raw::read_bare_int(&mut outer.reader)?; Ok(SeqDecoder { - outer: outer, + outer, tag: tag as u8, - length: length, + length, current: 0, }) } @@ -209,9 +206,9 @@ where fn byte_array(outer: &'a mut Decoder) -> Result { let length = raw::read_bare_int(&mut outer.reader)?; Ok(SeqDecoder { - outer: outer, + outer, tag: 0x01, - length: length, + length, current: 0, }) } @@ -219,9 +216,9 @@ where fn int_array(outer: &'a mut Decoder) -> Result { let length = raw::read_bare_int(&mut outer.reader)?; Ok(SeqDecoder { - outer: outer, + outer, tag: 0x03, - length: length, + length, current: 0, }) } @@ -278,7 +275,7 @@ impl<'a, 'b: 'a, 'de, R: io::Read> de::Deserializer<'de> for &'b mut InnerDecode where V: de::Visitor<'de>, { - let ref mut outer = self.outer; + let outer = &mut self.outer; match self.tag { 0x01 => visitor.visit_i8(raw::read_bare_byte(&mut outer.reader)?), @@ -304,7 +301,7 @@ impl<'a, 'b: 'a, 'de, R: io::Read> de::Deserializer<'de> for &'b mut InnerDecode { match self.tag { 0x01 => { - let ref mut reader = self.outer.reader; + let reader = &mut self.outer.reader; let value = raw::read_bare_byte(reader)?; match value { 0 => visitor.visit_bool(false), diff --git a/src/ser.rs b/src/ser.rs index 974dd28..1e3192f 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -62,10 +62,7 @@ where { /// Create an encoder with optional `header` from a given Writer. pub fn new(writer: W, header: Option<&'a str>) -> Self { - Encoder { - writer: writer, - header: header, - } + Encoder { writer, header } } /// Write the NBT tag and an optional header to the underlying writer. @@ -89,7 +86,7 @@ where W: io::Write, { pub fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self { - InnerEncoder { outer: outer } + InnerEncoder { outer } } } @@ -106,7 +103,7 @@ where { fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self { Compound { - outer: outer, + outer, length: 0, sigil: false, } @@ -119,8 +116,8 @@ where raw::write_bare_int(&mut outer.writer, 0)?; } Ok(Compound { - outer: outer, - length: length, + outer, + length, sigil: false, }) } @@ -383,7 +380,7 @@ where W: io::Write, { pub fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self { - MapKeyEncoder { outer: outer } + MapKeyEncoder { outer } } } @@ -435,10 +432,7 @@ where K: serde::Serialize, { fn from_outer(outer: &'a mut Encoder<'b, W>, key: Option) -> Self { - TagEncoder { - outer: outer, - key: key, - } + TagEncoder { outer, key } } fn write_header(&mut self, tag: i8) -> Result<()> { diff --git a/src/value.rs b/src/value.rs index fab0bae..e7b2fa4 100644 --- a/src/value.rs +++ b/src/value.rs @@ -82,7 +82,7 @@ impl Value { Value::List(ref vals) => { // This is a bit of a trick: if the list is empty, don't bother // checking its type. - if vals.len() == 0 { + if vals.is_empty() { dst.write_u8(0)?; // TAG_End dst.write_i32::(0)?; } else { @@ -171,7 +171,7 @@ impl Value { Value::IntArray(ref v) => write!(f, "{:?}", v), Value::LongArray(ref v) => write!(f, "{:?}", v), Value::List(ref v) => { - if v.len() == 0 { + if v.is_empty() { write!(f, "zero entries") } else { write!( @@ -191,7 +191,7 @@ impl Value { width = new_offset + tag.tag_name().len() )?; tag.print(f, new_offset)?; - write!(f, "\n")?; + writeln!(f)?; } write!(f, "{:>width$}", "}", width = offset + 1) } @@ -214,7 +214,7 @@ impl Value { width = new_offset + tag.tag_name().len() )?; tag.print(f, new_offset)?; - write!(f, "\n")?; + writeln!(f)?; } write!(f, "{:>width$}", "}", width = offset + 1) }