From 041deb5db65a6a4f4c3a9f7ab6a1ac56056c305a Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 9 Mar 2024 18:14:34 -0600 Subject: [PATCH] clippy --- simdnbt/benches/compare_realworld.rs | 4 +- simdnbt/examples/hypixel_no_derive.rs | 2 +- simdnbt/src/borrow/list.rs | 14 +++--- simdnbt/src/owned/list.rs | 61 +++++++++------------------ 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/simdnbt/benches/compare_realworld.rs b/simdnbt/benches/compare_realworld.rs index 1c50ce0..d93771b 100644 --- a/simdnbt/benches/compare_realworld.rs +++ b/simdnbt/benches/compare_realworld.rs @@ -125,7 +125,7 @@ fn simdnbt_items_from_nbt(nbt: simdnbt::borrow::BaseNbt) -> Option Option>> { .and_then(|textures| { if let azalea_nbt::NbtList::Compound(textures) = textures { textures - .get(0) + .first() .and_then(|texture| texture.get("Value")) .and_then(|value| value.as_string().cloned()) .map(|string| string.to_string()) diff --git a/simdnbt/examples/hypixel_no_derive.rs b/simdnbt/examples/hypixel_no_derive.rs index 4660fe5..446cbe1 100644 --- a/simdnbt/examples/hypixel_no_derive.rs +++ b/simdnbt/examples/hypixel_no_derive.rs @@ -57,7 +57,7 @@ fn items_from_nbt(nbt: BaseNbt) -> Option>> { .and_then(|skull_owner| skull_owner.compound("Properties")) .and_then(|properties| properties.list("textures")) .and_then(|textures| textures.compounds()) - .and_then(|textures| textures.get(0)) + .and_then(|textures| textures.first()) .and_then(|texture| texture.string("Value")) // the real program does some base64+json decoding here but that's unnecessary for the benchmark .map(|value| value.to_string()), diff --git a/simdnbt/src/borrow/list.rs b/simdnbt/src/borrow/list.rs index e3e0ca9..4cffd2b 100644 --- a/simdnbt/src/borrow/list.rs +++ b/simdnbt/src/borrow/list.rs @@ -315,27 +315,23 @@ impl<'a> NbtList<'a> { NbtList::Short(shorts) => shorts .to_vec() .into_iter() - .map(|short| super::NbtTag::Short(short)) - .collect(), - NbtList::Int(ints) => ints - .to_vec() - .into_iter() - .map(|int| super::NbtTag::Int(int)) + .map(super::NbtTag::Short) .collect(), + NbtList::Int(ints) => ints.to_vec().into_iter().map(super::NbtTag::Int).collect(), NbtList::Long(longs) => longs .to_vec() .into_iter() - .map(|long| super::NbtTag::Long(long)) + .map(super::NbtTag::Long) .collect(), NbtList::Float(floats) => floats .to_vec() .into_iter() - .map(|float| super::NbtTag::Float(float)) + .map(super::NbtTag::Float) .collect(), NbtList::Double(doubles) => doubles .to_vec() .into_iter() - .map(|double| super::NbtTag::Double(double)) + .map(super::NbtTag::Double) .collect(), NbtList::ByteArray(byte_arrays) => byte_arrays .iter() diff --git a/simdnbt/src/owned/list.rs b/simdnbt/src/owned/list.rs index 7e39622..9a0a219 100644 --- a/simdnbt/src/owned/list.rs +++ b/simdnbt/src/owned/list.rs @@ -355,60 +355,37 @@ impl NbtList { pub fn as_nbt_tags(&self) -> Vec { match self { NbtList::Empty => vec![], - NbtList::Byte(bytes) => bytes - .iter() - .map(|&byte| super::NbtTag::Byte(byte)) - .collect(), - NbtList::Short(shorts) => shorts - .to_vec() - .into_iter() - .map(|short| super::NbtTag::Short(short)) - .collect(), - NbtList::Int(ints) => ints - .to_vec() - .into_iter() - .map(|int| super::NbtTag::Int(int)) - .collect(), - NbtList::Long(longs) => longs - .to_vec() - .into_iter() - .map(|long| super::NbtTag::Long(long)) - .collect(), - NbtList::Float(floats) => floats - .to_vec() - .into_iter() - .map(|float| super::NbtTag::Float(float)) - .collect(), - NbtList::Double(doubles) => doubles - .to_vec() - .into_iter() - .map(|double| super::NbtTag::Double(double)) - .collect(), + NbtList::Byte(bytes) => bytes.iter().copied().map(super::NbtTag::Byte).collect(), + NbtList::Short(shorts) => shorts.iter().copied().map(super::NbtTag::Short).collect(), + NbtList::Int(ints) => ints.iter().copied().map(super::NbtTag::Int).collect(), + NbtList::Long(longs) => longs.iter().copied().map(super::NbtTag::Long).collect(), + NbtList::Float(floats) => floats.iter().copied().map(super::NbtTag::Float).collect(), + NbtList::Double(doubles) => { + doubles.iter().copied().map(super::NbtTag::Double).collect() + } NbtList::ByteArray(byte_arrays) => byte_arrays .iter() .cloned() - .map(|array| super::NbtTag::ByteArray(array)) - .collect(), - NbtList::String(strings) => strings - .iter() - .cloned() - .map(|string| super::NbtTag::String(string)) - .collect(), - NbtList::List(lists) => lists - .iter() - .map(|list| super::NbtTag::List(list.clone())) + .map(super::NbtTag::ByteArray) .collect(), + NbtList::String(strings) => { + strings.iter().cloned().map(super::NbtTag::String).collect() + } + NbtList::List(lists) => lists.iter().cloned().map(super::NbtTag::List).collect(), NbtList::Compound(compounds) => compounds .iter() - .map(|compound| super::NbtTag::Compound(compound.clone())) + .cloned() + .map(super::NbtTag::Compound) .collect(), NbtList::IntArray(int_arrays) => int_arrays .iter() - .map(|array| super::NbtTag::IntArray(array.clone())) + .cloned() + .map(super::NbtTag::IntArray) .collect(), NbtList::LongArray(long_arrays) => long_arrays .iter() - .map(|array| super::NbtTag::LongArray(array.clone())) + .cloned() + .map(super::NbtTag::LongArray) .collect(), } }