mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 22:52:32 +00:00
fix clippy warnings
This commit is contained in:
parent
a348f67b96
commit
98224cf913
9 changed files with 18 additions and 31 deletions
|
@ -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> {
|
fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result<String, BufReadError> {
|
||||||
let length = u32::var_read_from(buf)?;
|
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
|
// 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 {
|
return Err(BufReadError::StringLengthTooLong {
|
||||||
length,
|
length,
|
||||||
max_length: max_length * 4,
|
max_length: max_length * 4,
|
||||||
|
|
|
@ -274,7 +274,7 @@ impl TryFrom<ChatFormatting> for TextColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
// these are options instead of just bools because None is different than false in this case
|
// these are options instead of just bools because None is different than false in this case
|
||||||
pub color: Option<TextColor>,
|
pub color: Option<TextColor>,
|
||||||
|
@ -288,20 +288,8 @@ pub struct Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Style {
|
impl Style {
|
||||||
pub fn default() -> Self {
|
|
||||||
Self::empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self::default()
|
||||||
color: None,
|
|
||||||
bold: None,
|
|
||||||
italic: None,
|
|
||||||
underlined: None,
|
|
||||||
strikethrough: None,
|
|
||||||
obfuscated: None,
|
|
||||||
reset: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize(json: &Value) -> Style {
|
pub fn deserialize(json: &Value) -> Style {
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl Tag {
|
||||||
if length * 4 > (stream.get_ref().len() - stream.position() as usize) {
|
if length * 4 > (stream.get_ref().len() - stream.position() as usize) {
|
||||||
return Err(Error::UnexpectedEof);
|
return Err(Error::UnexpectedEof);
|
||||||
}
|
}
|
||||||
let mut ints = Vec::with_capacity(length as usize);
|
let mut ints = Vec::with_capacity(length);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
ints.push(stream.read_i32::<BE>()?);
|
ints.push(stream.read_i32::<BE>()?);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ impl Tag {
|
||||||
if length * 8 > (stream.get_ref().len() - stream.position() as usize) {
|
if length * 8 > (stream.get_ref().len() - stream.position() as usize) {
|
||||||
return Err(Error::UnexpectedEof);
|
return Err(Error::UnexpectedEof);
|
||||||
}
|
}
|
||||||
let mut longs = Vec::with_capacity(length as usize);
|
let mut longs = Vec::with_capacity(length);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
longs.push(stream.read_i64::<BE>()?);
|
longs.push(stream.read_i64::<BE>()?);
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,8 +338,7 @@ impl From<&DiscreteVoxelShape> for BitSetDiscreteVoxelShape {
|
||||||
for y in 0..y_size {
|
for y in 0..y_size {
|
||||||
for z in 0..z_size {
|
for z in 0..z_size {
|
||||||
if shape.is_full(x, y, z) {
|
if shape.is_full(x, y, z) {
|
||||||
storage
|
storage.set(Self::get_index_from_size(x, y, z, y_size, z_size));
|
||||||
.set(Self::get_index_from_size(x, y, z, y_size, z_size) as usize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ fn parse_frame(buffer: &mut BytesMut) -> Result<BytesMut, FrameSplitterError> {
|
||||||
Ok(data)
|
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
|
// https://tokio.rs/tokio/tutorial/framing
|
||||||
let read_frame = parse_frame(buffer);
|
let read_frame = parse_frame(buffer);
|
||||||
match read_frame {
|
match read_frame {
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn packet_encoder<P: ProtocolPacket + std::fmt::Debug>(
|
||||||
packet: &P,
|
packet: &P,
|
||||||
) -> Result<Vec<u8>, PacketEncodeError> {
|
) -> Result<Vec<u8>, PacketEncodeError> {
|
||||||
let mut buf = Vec::new();
|
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)?;
|
packet.write(&mut buf)?;
|
||||||
if buf.len() > MAXIMUM_UNCOMPRESSED_LENGTH as usize {
|
if buf.len() > MAXIMUM_UNCOMPRESSED_LENGTH as usize {
|
||||||
return Err(PacketEncodeError::TooBig {
|
return Err(PacketEncodeError::TooBig {
|
||||||
|
|
|
@ -120,21 +120,21 @@ impl BitStorage {
|
||||||
|
|
||||||
let values_per_long = 64 / bits;
|
let values_per_long = 64 / bits;
|
||||||
let magic_index = values_per_long - 1;
|
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 calculated_length = (size + values_per_long - 1) / values_per_long;
|
||||||
|
|
||||||
let mask = (1 << bits) - 1;
|
let mask = (1 << bits) - 1;
|
||||||
|
|
||||||
let using_data = if let Some(data) = data {
|
let using_data = if let Some(data) = data {
|
||||||
if data.len() != calculated_length as usize {
|
if data.len() != calculated_length {
|
||||||
return Err(BitStorageError::InvalidLength {
|
return Err(BitStorageError::InvalidLength {
|
||||||
got: data.len(),
|
got: data.len(),
|
||||||
expected: calculated_length as usize,
|
expected: calculated_length,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
} else {
|
} else {
|
||||||
vec![0; calculated_length as usize]
|
vec![0; calculated_length]
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(BitStorage {
|
Ok(BitStorage {
|
||||||
|
@ -179,7 +179,7 @@ impl BitStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
let cell_index = self.cell_index(index as u64);
|
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;
|
let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
|
||||||
cell >> bit_index & self.mask
|
cell >> bit_index & self.mask
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ impl BitStorage {
|
||||||
assert!(index < self.size);
|
assert!(index < self.size);
|
||||||
assert!(value <= self.mask);
|
assert!(value <= self.mask);
|
||||||
let cell_index = self.cell_index(index as u64);
|
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 bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
|
||||||
let old_value = *cell >> (bit_index as u64) & self.mask;
|
let old_value = *cell >> (bit_index as u64) & self.mask;
|
||||||
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
||||||
|
@ -209,7 +209,7 @@ impl BitStorage {
|
||||||
assert!(index < self.size);
|
assert!(index < self.size);
|
||||||
assert!(value <= self.mask);
|
assert!(value <= self.mask);
|
||||||
let cell_index = self.cell_index(index as u64);
|
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 bit_index = (index - cell_index * self.values_per_long as usize) * self.bits;
|
||||||
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl McBufReadable for EntityDataValue {
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some((val - 1) as u32)
|
Some(val - 1)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
18 => EntityDataValue::Pose(Pose::read_from(buf)?),
|
18 => EntityDataValue::Pose(Pose::read_from(buf)?),
|
||||||
|
|
|
@ -149,7 +149,7 @@ impl PalettedContainer {
|
||||||
}
|
}
|
||||||
Palette::Linear(palette) => {
|
Palette::Linear(palette) => {
|
||||||
if let Some(index) = palette.iter().position(|v| *v == value) {
|
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());
|
let capacity = 2usize.pow(self.bits_per_entry.into());
|
||||||
if capacity > palette.len() {
|
if capacity > palette.len() {
|
||||||
|
@ -162,7 +162,7 @@ impl PalettedContainer {
|
||||||
Palette::Hashmap(palette) => {
|
Palette::Hashmap(palette) => {
|
||||||
// TODO? vanilla keeps this in memory as a hashmap, but also i don't care
|
// 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) {
|
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());
|
let capacity = 2usize.pow(self.bits_per_entry.into());
|
||||||
if capacity > palette.len() {
|
if capacity > palette.len() {
|
||||||
|
|
Loading…
Reference in a new issue