Skip to content

Commit

Permalink
Fix existing clippy lints.
Browse files Browse the repository at this point in the history
Closes #49.
  • Loading branch information
atheriel committed Jun 16, 2020
1 parent a4b4b96 commit 2db331c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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, "}}")
}
Expand Down
23 changes: 10 additions & 13 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ where
R: io::Read,
{
fn new(outer: &'a mut Decoder<R>) -> Self {
MapDecoder {
outer: outer,
tag: None,
}
MapDecoder { outer, tag: None }
}
}

Expand Down Expand Up @@ -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!(),
};
Expand All @@ -199,29 +196,29 @@ 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,
})
}

fn byte_array(outer: &'a mut Decoder<R>) -> Result<Self> {
let length = raw::read_bare_int(&mut outer.reader)?;
Ok(SeqDecoder {
outer: outer,
outer,
tag: 0x01,
length: length,
length,
current: 0,
})
}

fn int_array(outer: &'a mut Decoder<R>) -> Result<Self> {
let length = raw::read_bare_int(&mut outer.reader)?;
Ok(SeqDecoder {
outer: outer,
outer,
tag: 0x03,
length: length,
length,
current: 0,
})
}
Expand Down Expand Up @@ -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)?),
Expand All @@ -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),
Expand Down
20 changes: 7 additions & 13 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -89,7 +86,7 @@ where
W: io::Write,
{
pub fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self {
InnerEncoder { outer: outer }
InnerEncoder { outer }
}
}

Expand All @@ -106,7 +103,7 @@ where
{
fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self {
Compound {
outer: outer,
outer,
length: 0,
sigil: false,
}
Expand All @@ -119,8 +116,8 @@ where
raw::write_bare_int(&mut outer.writer, 0)?;
}
Ok(Compound {
outer: outer,
length: length,
outer,
length,
sigil: false,
})
}
Expand Down Expand Up @@ -383,7 +380,7 @@ where
W: io::Write,
{
pub fn from_outer(outer: &'a mut Encoder<'b, W>) -> Self {
MapKeyEncoder { outer: outer }
MapKeyEncoder { outer }
}
}

Expand Down Expand Up @@ -435,10 +432,7 @@ where
K: serde::Serialize,
{
fn from_outer(outer: &'a mut Encoder<'b, W>, key: Option<K>) -> Self {
TagEncoder {
outer: outer,
key: key,
}
TagEncoder { outer, key }
}

fn write_header(&mut self, tag: i8) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BigEndian>(0)?;
} else {
Expand Down Expand Up @@ -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!(
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 2db331c

Please sign in to comment.