mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Protocols] Cargo clippy optimizations
This commit is contained in:
parent
e6562d30cb
commit
e163774685
13 changed files with 57 additions and 65 deletions
|
|
@ -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)?)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue