diff options
| author | Fuwn <[email protected]> | 2021-05-28 00:06:40 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-28 00:06:40 -0700 |
| commit | 179ce3277ece536cae41b834469f4065e3600d82 (patch) | |
| tree | a96d55a34531c9761f6309c35f8d9cfab9879db6 /crates/whirl_server/src/cmd/commands | |
| parent | Merge branch 'develop' of https://github.com/Whirlsplash/whirl into develop (diff) | |
| download | whirl-179ce3277ece536cae41b834469f4065e3600d82.tar.xz whirl-179ce3277ece536cae41b834469f4065e3600d82.zip | |
fix(global): a lot of clippy warnings
This change makes clippy **a lot** more strict.
Diffstat (limited to 'crates/whirl_server/src/cmd/commands')
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/action.rs | 5 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/buddy_list.rs | 11 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/property/create.rs | 8 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/redirect_id.rs | 11 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/subscribe_room.rs | 11 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/teleport.rs | 11 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/text.rs | 9 |
7 files changed, 36 insertions, 30 deletions
diff --git a/crates/whirl_server/src/cmd/commands/action.rs b/crates/whirl_server/src/cmd/commands/action.rs index 8d1fb0b..4ba7065 100644 --- a/crates/whirl_server/src/cmd/commands/action.rs +++ b/crates/whirl_server/src/cmd/commands/action.rs @@ -8,8 +8,9 @@ // of actions, it will be of2m-ified. use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; -pub fn create_action() -> Vec<u8> { +pub fn create() -> Vec<u8> { let mut command = BytesMut::new(); command.put_slice(&[ @@ -19,7 +20,7 @@ pub fn create_action() -> Vec<u8> { // Convert to vector and insert the length let mut command_as_vec = command.to_vec(); - command_as_vec.insert(0, command.len() as u8 + 1); + command_as_vec.insert(0, command.len().as_(): u8 + 1); // Return bytes command_as_vec diff --git a/crates/whirl_server/src/cmd/commands/buddy_list.rs b/crates/whirl_server/src/cmd/commands/buddy_list.rs index 9757519..f80c86d 100644 --- a/crates/whirl_server/src/cmd/commands/buddy_list.rs +++ b/crates/whirl_server/src/cmd/commands/buddy_list.rs @@ -4,6 +4,7 @@ use std::str::from_utf8; use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; use crate::cmd::{ constants::BUDDYLISTNOTIFY, @@ -22,7 +23,7 @@ impl Parsable for BuddyList { .to_string(), // Get the last byte - add: data[data[0] as usize - 1] as i8, + add: data[data[0] as usize - 1].as_(): i8, } } } @@ -32,15 +33,15 @@ impl Creatable for BuddyList { // Header command.put_u8(0x01); // ObjId - command.put_i8(BUDDYLISTNOTIFY as i8); // Type + command.put_i8(BUDDYLISTNOTIFY.as_(): i8); // Type // Content - command.put_u8(self.buddy.len() as u8); // Buddy (name) length + command.put_u8(self.buddy.len().as_(): u8); // Buddy (name) length command.put_slice(self.buddy.as_bytes()); // Buddy (name) - command.put_u8(self.add as u8); // "Is buddy logged on?" (?) + command.put_u8(self.add.as_(): u8); // "Is buddy logged on?" (?) let mut command_as_vec = command.to_vec(); - command_as_vec.insert(0, command.len() as u8 + 1); + command_as_vec.insert(0, command.len().as_(): u8 + 1); command_as_vec } diff --git a/crates/whirl_server/src/cmd/commands/property/create.rs b/crates/whirl_server/src/cmd/commands/property/create.rs index 40ec2be..94cf75b 100644 --- a/crates/whirl_server/src/cmd/commands/property/create.rs +++ b/crates/whirl_server/src/cmd/commands/property/create.rs @@ -27,7 +27,7 @@ use crate::{ }, }; -pub fn create_property_update_as_distributor() -> Vec<u8> { +pub fn property_update_as_distributor() -> Vec<u8> { property_list_to_bytes( PROPUPD, 0xFF, @@ -64,7 +64,7 @@ pub fn create_property_update_as_distributor() -> Vec<u8> { ) } -pub fn create_property_update_as_hub() -> Vec<u8> { +pub fn property_update_as_hub() -> Vec<u8> { property_list_to_bytes( PROPUPD, 0xFF, @@ -105,7 +105,7 @@ pub fn create_property_update_as_hub() -> Vec<u8> { ) } -pub fn create_property_request_as_distributor() -> Vec<u8> { +pub fn property_request_as_distributor() -> Vec<u8> { property_list_to_bytes( SESSINIT as i32, 0x01, @@ -142,7 +142,7 @@ pub fn create_property_request_as_distributor() -> Vec<u8> { ) } -pub fn create_property_request_as_hub() -> Vec<u8> { +pub fn property_request_as_hub() -> Vec<u8> { property_list_to_bytes( SESSINIT as i32, 0x01, diff --git a/crates/whirl_server/src/cmd/commands/redirect_id.rs b/crates/whirl_server/src/cmd/commands/redirect_id.rs index 942c06d..9727107 100644 --- a/crates/whirl_server/src/cmd/commands/redirect_id.rs +++ b/crates/whirl_server/src/cmd/commands/redirect_id.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; use whirl_config::Config; use crate::cmd::{constants::REDIRID, extendable::Creatable}; @@ -17,24 +18,24 @@ impl Creatable for RedirectId { // Header command.put_u8(0x01); // ObjId - command.put_u8(REDIRID as u8); // Type + command.put_u8(REDIRID.as_(): u8); // Type // Content - command.put_u8(self.room_name.len() as u8); // Room name length + command.put_u8(self.room_name.len().as_(): u8); // Room name length command.put_slice(self.room_name.as_bytes()); // Room name // command.put_u8(0x00); // Unimplemented byte (?) // command.put_u8(room_id); // Room ID - command.put_u16(self.room_number as u16); // Room ID + command.put_u16(self.room_number.as_(): u16); // Room ID // IP for byte in Config::get().whirlsplash.ip.split('.') { command.put_u8(byte.parse::<u8>().unwrap()); } - command.put_u16(Config::get().hub.port as u16); // Port + command.put_u16(Config::get().hub.port.as_(): u16); // Port // Length let mut command_as_vec = command.to_vec(); - command_as_vec.insert(0, command.len() as u8 + 1); + command_as_vec.insert(0, command.len().as_(): u8 + 1); // Return command_as_vec diff --git a/crates/whirl_server/src/cmd/commands/subscribe_room.rs b/crates/whirl_server/src/cmd/commands/subscribe_room.rs index 9e7d732..8ed4876 100644 --- a/crates/whirl_server/src/cmd/commands/subscribe_room.rs +++ b/crates/whirl_server/src/cmd/commands/subscribe_room.rs @@ -3,6 +3,7 @@ use byteorder::{BigEndian, ReadBytesExt}; use bytes::{Buf, BytesMut}; +use num_traits::AsPrimitive; use crate::cmd::extendable::Parsable; @@ -20,11 +21,11 @@ impl Parsable for SubscribeRoom { let mut data = BytesMut::from(data.as_slice()).reader(); Self { - room_number: data.read_i16::<BigEndian>().unwrap() as i8, - x: data.read_i16::<BigEndian>().unwrap() as i8 as f32, - y: data.read_i16::<BigEndian>().unwrap() as i8 as f32, - z: data.read_i16::<BigEndian>().unwrap() as i8 as f32, - distance: data.read_i16::<BigEndian>().unwrap() as i8 as f32, // + 100 + room_number: data.read_i16::<BigEndian>().unwrap().as_(): i8, + x: f32::from(data.read_i16::<BigEndian>().unwrap().as_(): i8), + y: f32::from(data.read_i16::<BigEndian>().unwrap().as_(): i8), + z: f32::from(data.read_i16::<BigEndian>().unwrap().as_(): i8), + distance: f32::from(data.read_i16::<BigEndian>().unwrap().as_(): i8), // + 100 } } } diff --git a/crates/whirl_server/src/cmd/commands/teleport.rs b/crates/whirl_server/src/cmd/commands/teleport.rs index ef8f6b2..39c78f9 100644 --- a/crates/whirl_server/src/cmd/commands/teleport.rs +++ b/crates/whirl_server/src/cmd/commands/teleport.rs @@ -3,6 +3,7 @@ use byteorder::{BigEndian, ReadBytesExt}; use bytes::{Buf, BytesMut}; +use num_traits::AsPrimitive; use crate::cmd::extendable::Parsable; @@ -22,13 +23,13 @@ impl Parsable for Teleport { let mut data = BytesMut::from(data.as_slice()).reader(); Self { - room_id: data.read_u16::<BigEndian>().unwrap() as i8, + room_id: data.read_u16::<BigEndian>().unwrap().as_(): i8, exit_type: data.read_u8().unwrap(), entry_type: data.read_u8().unwrap(), - x: data.read_i16::<BigEndian>().unwrap() as f32, - y: data.read_i16::<BigEndian>().unwrap() as f32, - z: data.read_i16::<BigEndian>().unwrap() as f32, - direction: data.read_i16::<BigEndian>().unwrap() as f32, + x: f32::from(data.read_i16::<BigEndian>().unwrap()), + y: f32::from(data.read_i16::<BigEndian>().unwrap()), + z: f32::from(data.read_i16::<BigEndian>().unwrap()), + direction: f32::from(data.read_i16::<BigEndian>().unwrap()), } } } diff --git a/crates/whirl_server/src/cmd/commands/text.rs b/crates/whirl_server/src/cmd/commands/text.rs index 9f3fb00..414dc64 100644 --- a/crates/whirl_server/src/cmd/commands/text.rs +++ b/crates/whirl_server/src/cmd/commands/text.rs @@ -4,6 +4,7 @@ use std::str::from_utf8; use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; use crate::cmd::{ constants::TEXT, @@ -20,7 +21,7 @@ impl Creatable for Text { // Header command.put_u8(0x01); - command.put_i8(TEXT as i8); + command.put_i8(TEXT.as_(): i8); // Content // TODO: Find a way to parse ObjIds. @@ -28,14 +29,14 @@ impl Creatable for Text { // The below byte is suspected to be the sender's short ObjId. command.put_i8(0x00); - command.put_u8(self.sender.len() as u8); + command.put_u8(self.sender.len().as_(): u8); command.put_slice(self.sender.as_bytes()); - command.put_u8(self.content.len() as u8); + command.put_u8(self.content.len().as_(): u8); command.put_slice(self.content.as_bytes()); // Convert to vector and insert the length let mut command_as_vec = command.to_vec(); - command_as_vec.insert(0, command.len() as u8 + 1); + command_as_vec.insert(0, command.len().as_(): u8 + 1); // Return bytes command_as_vec |