[Protocols] Cargo clippy optimizations

This commit is contained in:
CosminPerRam 2023-03-09 01:30:28 +02:00
parent e6562d30cb
commit e163774685
13 changed files with 57 additions and 65 deletions

View file

@ -71,7 +71,7 @@ impl Bedrock {
error_by_expected_size(remaining_length, buffer.remaining_length())?;
let binding = buffer.get_string_utf8_unended()?;
let status: Vec<&str> = binding.split(";").collect();
let status: Vec<&str> = binding.split(';').collect();
// We must have at least 6 values
if status.len() < 6 {
@ -85,8 +85,8 @@ impl Bedrock {
version_protocol: status[2].to_string(),
players_maximum: status[5].parse().map_err(|_| TypeParse)?,
players_online: status[4].parse().map_err(|_| TypeParse)?,
id: status.get(6).and_then(|v| Some(v.to_string())),
map: status.get(7).and_then(|v| Some(v.to_string())),
id: status.get(6).map(|v| v.to_string()),
map: status.get(7).map(|v| v.to_string()),
game_mode: match status.get(8) {
None => None,
Some(v) => Some(GameMode::from_bedrock(v)?)

View file

@ -39,7 +39,7 @@ impl LegacyBV1_8 {
let packet_string = buffer.get_string_utf16()?;
let split: Vec<&str> = packet_string.split("§").collect();
let split: Vec<&str> = packet_string.split('§').collect();
error_by_expected_size(3, split.len())?;
let description = split[0].to_string();

View file

@ -44,7 +44,7 @@ impl LegacyV1_4 {
let packet_string = buffer.get_string_utf16()?;
let split: Vec<&str> = packet_string.split("§").collect();
let split: Vec<&str> = packet_string.split('§').collect();
error_by_expected_size(3, split.len())?;
let description = split[0].to_string();

View file

@ -49,7 +49,7 @@ impl LegacyV1_6 {
pub fn get_response(buffer: &mut Bufferer) -> GDResult<JavaResponse> {
let packet_string = buffer.get_string_utf16()?;
let split: Vec<&str> = packet_string.split("\x00").collect();
let split: Vec<&str> = packet_string.split('\x00').collect();
error_by_expected_size(5, split.len())?;
let version_protocol = split[0].parse()

View file

@ -174,14 +174,13 @@ pub(crate) fn as_varint(value: i32) -> Vec<u8> {
pub(crate) fn get_string(buffer: &mut Bufferer) -> GDResult<String> {
let length = get_varint(buffer)? as usize;
let mut text = vec![0; length];
let mut text = Vec::with_capacity(length);
for i in 0..length {
text[i] = buffer.get_u8()?;
for _ in 0..length {
text.push(buffer.get_u8()?)
}
Ok(String::from_utf8(text)
.map_err(|_| PacketBad)?)
String::from_utf8(text).map_err(|_| PacketBad)
}
#[allow(dead_code)]