chore: clippy enforce unwrap_used, expect_used and panic
release is not far
This commit is contained in:
1 parent
0eb7b936db
commit
49360e53ef
291 files changed
+3200
-1783
No files matched your search
@@ -4,6 +4,9 @@
|
||||
//! NBT, Bedrock network NBT, and gzip-compressed NBT. Data is handled directly
|
||||
//! via [`Nbt`], [`NbtCompound`], and [`NbtTag`].
|
||||
|
||||
#![deny(clippy::unwrap_used)]
|
||||
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
|
||||
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
ops::Deref,
|
||||
@@ -156,11 +159,13 @@ impl Nbt {
|
||||
pub fn write(self) -> Bytes {
|
||||
let mut bytes = Vec::new();
|
||||
let mut writer = NbtWriteHelperJava::new(&mut bytes);
|
||||
writer.write_u8(COMPOUND_ID).unwrap();
|
||||
NbtTag::String(self.name.into())
|
||||
.serialize_data(&mut writer)
|
||||
.unwrap();
|
||||
self.root_tag.serialize_content(&mut writer).unwrap();
|
||||
if writer.write_u8(COMPOUND_ID).is_ok()
|
||||
&& NbtTag::String(self.name.into())
|
||||
.serialize_data(&mut writer)
|
||||
.is_ok()
|
||||
{
|
||||
let _ = self.root_tag.serialize_content(&mut writer);
|
||||
}
|
||||
|
||||
bytes.into()
|
||||
}
|
||||
@@ -170,11 +175,13 @@ impl Nbt {
|
||||
pub fn write_bedrock(self) -> Bytes {
|
||||
let mut bytes = Vec::new();
|
||||
let mut writer = NbtWriteHelperBedrock::new(&mut bytes);
|
||||
writer.write_u8(COMPOUND_ID).unwrap();
|
||||
NbtTag::String(self.name.into())
|
||||
.serialize_data(&mut writer)
|
||||
.unwrap();
|
||||
self.root_tag.serialize_content(&mut writer).unwrap();
|
||||
if writer.write_u8(COMPOUND_ID).is_ok()
|
||||
&& NbtTag::String(self.name.into())
|
||||
.serialize_data(&mut writer)
|
||||
.is_ok()
|
||||
{
|
||||
let _ = self.root_tag.serialize_content(&mut writer);
|
||||
}
|
||||
|
||||
bytes.into()
|
||||
}
|
||||
@@ -197,8 +204,9 @@ impl Nbt {
|
||||
let mut bytes = Vec::new();
|
||||
let mut writer = NbtWriteHelperJava::new(&mut bytes);
|
||||
|
||||
writer.write_u8(COMPOUND_ID).unwrap();
|
||||
self.root_tag.serialize_content(&mut writer).unwrap();
|
||||
if writer.write_u8(COMPOUND_ID).is_ok() {
|
||||
let _ = self.root_tag.serialize_content(&mut writer);
|
||||
}
|
||||
|
||||
bytes.into()
|
||||
}
|
||||
|
||||
@@ -141,14 +141,12 @@ impl DynamicOps for NbtOps {
|
||||
NbtTag::List(l) => {
|
||||
// Check the type of this list.
|
||||
// If the list contains compounds, we try unwrapping them.
|
||||
if !l.is_empty()
|
||||
&& let NbtTag::Compound(_) = l.first().unwrap()
|
||||
{
|
||||
if let Some(NbtTag::Compound(_)) = l.first() {
|
||||
DataResult::new_success(NbtIter::CompoundList(l.into_iter().map(|c| {
|
||||
if let NbtTag::Compound(compound) = c {
|
||||
Self::try_unwrap(compound)
|
||||
} else {
|
||||
c.clone()
|
||||
c
|
||||
}
|
||||
})))
|
||||
} else {
|
||||
@@ -242,8 +240,13 @@ impl DynamicOps for NbtOps {
|
||||
} else {
|
||||
NbtCompound::new()
|
||||
};
|
||||
compound.put(key.extract_string().unwrap(), value);
|
||||
DataResult::new_success(compound.into())
|
||||
key.extract_string().map_or_else(
|
||||
|| DataResult::new_error(format!("Key is not a string: {key}")),
|
||||
|key_str| {
|
||||
compound.put(key_str, value);
|
||||
DataResult::new_success(compound.into())
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +337,10 @@ impl NbtOps {
|
||||
fn try_unwrap(mut compound: NbtCompound) -> NbtTag {
|
||||
if compound.child_tags.len() == 1 && compound.has("") {
|
||||
// Remove the element to own the contained tag.
|
||||
compound.child_tags.remove("").unwrap()
|
||||
compound
|
||||
.child_tags
|
||||
.remove("")
|
||||
.unwrap_or_else(|| NbtTag::from(compound))
|
||||
} else {
|
||||
NbtTag::from(compound)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,10 @@ impl NbtTag {
|
||||
if let Self::Compound(mut compound) = tag {
|
||||
// Try to get the wrapped tag, stored by "".
|
||||
if Self::is_wrapper_compound(&compound) {
|
||||
compound.child_tags.remove("").unwrap()
|
||||
compound
|
||||
.child_tags
|
||||
.remove("")
|
||||
.unwrap_or(Self::Compound(compound))
|
||||
} else {
|
||||
Self::Compound(compound)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user