fix clippy warnings

This commit is contained in:
mat 2022-10-15 16:53:34 -05:00
parent a348f67b96
commit 98224cf913
9 changed files with 18 additions and 31 deletions

View file

@ -57,7 +57,7 @@ fn read_bytes<'a>(buf: &'a mut Cursor<&[u8]>, length: usize) -> Result<&'a [u8],
fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result<String, BufReadError> {
let length = u32::var_read_from(buf)?;
// i don't know why it's multiplied by 4 but it's like that in mojang's code so
if length as u32 > max_length * 4 {
if length > max_length * 4 {
return Err(BufReadError::StringLengthTooLong {
length,
max_length: max_length * 4,

View file

@ -274,7 +274,7 @@ impl TryFrom<ChatFormatting> for TextColor {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Style {
// these are options instead of just bools because None is different than false in this case
pub color: Option<TextColor>,
@ -288,20 +288,8 @@ pub struct Style {
}
impl Style {
pub fn default() -> Self {
Self::empty()
}
pub fn empty() -> Self {
Self {
color: None,
bold: None,
italic: None,
underlined: None,
strikethrough: None,
obfuscated: None,
reset: false,
}
Self::default()
}
pub fn deserialize(json: &Value) -> Style {

View file

@ -98,7 +98,7 @@ impl Tag {
if length * 4 > (stream.get_ref().len() - stream.position() as usize) {
return Err(Error::UnexpectedEof);
}
let mut ints = Vec::with_capacity(length as usize);
let mut ints = Vec::with_capacity(length);
for _ in 0..length {
ints.push(stream.read_i32::<BE>()?);
}
@ -111,7 +111,7 @@ impl Tag {
if length * 8 > (stream.get_ref().len() - stream.position() as usize) {
return Err(Error::UnexpectedEof);
}
let mut longs = Vec::with_capacity(length as usize);
let mut longs = Vec::with_capacity(length);
for _ in 0..length {
longs.push(stream.read_i64::<BE>()?);
}

View file

@ -338,8 +338,7 @@ impl From<&DiscreteVoxelShape> for BitSetDiscreteVoxelShape {
for y in 0..y_size {
for z in 0..z_size {
if shape.is_full(x, y, z) {
storage
.set(Self::get_index_from_size(x, y, z, y_size, z_size) as usize);
storage.set(Self::get_index_from_size(x, y, z, y_size, z_size));
}
}
}

View file

@ -106,7 +106,7 @@ fn parse_frame(buffer: &mut BytesMut) -> Result<BytesMut, FrameSplitterError> {
Ok(data)
}
fn frame_splitter<'a>(buffer: &'a mut BytesMut) -> Result<Option<Vec<u8>>, FrameSplitterError> {
fn frame_splitter(buffer: &mut BytesMut) -> Result<Option<Vec<u8>>, FrameSplitterError> {
// https://tokio.rs/tokio/tutorial/framing
let read_frame = parse_frame(buffer);
match read_frame {

View file

@ -29,7 +29,7 @@ fn packet_encoder<P: ProtocolPacket + std::fmt::Debug>(
packet: &P,
) -> Result<Vec<u8>, PacketEncodeError> {
let mut buf = Vec::new();
(packet.id() as u32).var_write_into(&mut buf)?;
packet.id().var_write_into(&mut buf)?;
packet.write(&mut buf)?;
if buf.len() > MAXIMUM_UNCOMPRESSED_LENGTH as usize {
return Err(PacketEncodeError::TooBig {

View file

@ -120,21 +120,21 @@ impl BitStorage {
let values_per_long = 64 / bits;
let magic_index = values_per_long - 1;
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize];
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index];
let calculated_length = (size + values_per_long - 1) / values_per_long;
let mask = (1 << bits) - 1;
let using_data = if let Some(data) = data {
if data.len() != calculated_length as usize {
if data.len() != calculated_length {
return Err(BitStorageError::InvalidLength {
got: data.len(),
expected: calculated_length as usize,
expected: calculated_length,
});
}
data
} else {
vec![0; calculated_length as usize]
vec![0; calculated_length]
};
Ok(BitStorage {
@ -179,7 +179,7 @@ impl BitStorage {
}
let cell_index = self.cell_index(index as u64);
let cell = &self.data[cell_index as usize];
let cell = &self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
cell >> bit_index & self.mask
}
@ -193,7 +193,7 @@ impl BitStorage {
assert!(index < self.size);
assert!(value <= self.mask);
let cell_index = self.cell_index(index as u64);
let cell = &mut self.data[cell_index as usize];
let cell = &mut self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
let old_value = *cell >> (bit_index as u64) & self.mask;
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
@ -209,7 +209,7 @@ impl BitStorage {
assert!(index < self.size);
assert!(value <= self.mask);
let cell_index = self.cell_index(index as u64);
let cell = &mut self.data[cell_index as usize];
let cell = &mut self.data[cell_index];
let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
}

View file

@ -110,7 +110,7 @@ impl McBufReadable for EntityDataValue {
if val == 0 {
None
} else {
Some((val - 1) as u32)
Some(val - 1)
}
}),
18 => EntityDataValue::Pose(Pose::read_from(buf)?),

View file

@ -149,7 +149,7 @@ impl PalettedContainer {
}
Palette::Linear(palette) => {
if let Some(index) = palette.iter().position(|v| *v == value) {
return index as usize;
return index;
}
let capacity = 2usize.pow(self.bits_per_entry.into());
if capacity > palette.len() {
@ -162,7 +162,7 @@ impl PalettedContainer {
Palette::Hashmap(palette) => {
// TODO? vanilla keeps this in memory as a hashmap, but also i don't care
if let Some(index) = palette.iter().position(|v| *v == value) {
return index as usize;
return index;
}
let capacity = 2usize.pow(self.bits_per_entry.into());
if capacity > palette.len() {