From f3682d0b8224fcb4d1552b7c3e75c2a5e3a3d3b2 Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 30 Jan 2023 18:05:36 -0700 Subject: [PATCH] clippy --- src/bin/main.rs | 2 +- src/entity/character.rs | 4 ++-- src/entity/gateway/entitygateway.rs | 1 - src/entity/gateway/postgres/postgres.rs | 4 ++-- src/lib.rs | 1 + src/login/character.rs | 2 +- src/patch/patch.rs | 6 +++--- src/ship/drops/mod.rs | 2 +- src/ship/items/apply_item.rs | 23 +++++------------------ src/ship/items/state.rs | 2 +- src/ship/map/enemy.rs | 2 +- src/ship/packet/handler/room.rs | 1 + src/ship/packet/handler/settings.rs | 2 +- src/ship/room.rs | 12 ++---------- src/ship/ship.rs | 13 ++----------- 15 files changed, 24 insertions(+), 53 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 2b262fc..9ff056b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -52,7 +52,7 @@ fn main() { for i in 0..5 { let fake_user = NewUserAccountEntity { - email: format!("fake{}@email.com", i), + email: format!("fake{i}@email.com"), username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) }, password: bcrypt::hash("qwer", 5).unwrap(), guildcard: i + 1, diff --git a/src/entity/character.rs b/src/entity/character.rs index ddf892a..080bb1b 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -2,8 +2,8 @@ use std::convert::{From, Into}; use std::collections::HashMap; use serde::{Serialize, Deserialize}; -use libpso::packet::ship::{UpdateConfig, WriteInfoboard, KeyboardConfig, GamepadConfig}; -use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU, DEFAULT_KEYBOARD_CONFIG1, DEFAULT_KEYBOARD_CONFIG2, DEFAULT_KEYBOARD_CONFIG3, DEFAULT_KEYBOARD_CONFIG4, DEFAULT_GAMEPAD_CONFIG}; +use libpso::packet::ship::{UpdateConfig, WriteInfoboard}; +use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU}; use crate::entity::item::tech::Technique; use crate::entity::account::UserAccountId; diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index c9cedc0..a8c47dc 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -1,4 +1,3 @@ -use std::convert::From; use thiserror::Error; use futures::Future; diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 0a81bb7..dbc49d4 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -2,7 +2,7 @@ #![allow(clippy::explicit_auto_deref)] use std::convert::{From, TryFrom, Into}; -use futures::{Future, TryStreamExt}; +use futures::Future; use async_std::stream::StreamExt; use async_std::sync::{Arc, Mutex}; use libpso::character::guildcard; @@ -67,7 +67,7 @@ impl<'t> PostgresGateway<'t> { let pool = async_std::task::block_on(async move { PgPoolOptions::new() .max_connections(5) - .connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap() + .connect(&format!("postgresql://{username}:{password}@{host}:5432/{dbname}")).await.unwrap() }); PostgresGateway { diff --git a/src/lib.rs b/src/lib.rs index 2c1ab47..2c3d9c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::type_complexity)] #![allow(incomplete_features)] #![feature(inline_const)] #![feature(drain_filter)] diff --git a/src/login/character.rs b/src/login/character.rs index 7f626cf..349d1dd 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -393,7 +393,7 @@ impl CharacterServerState { Ok(settings) => settings, Err(_) => { let user_settings = NewUserSettingsEntity::new(user.id); - self.entity_gateway.create_user_settings(user_settings).await.map_err(|err| CharacterError::CouldNotLoadSettings(err))? + self.entity_gateway.create_user_settings(user_settings).await.map_err(CharacterError::CouldNotLoadSettings)? } }; diff --git a/src/patch/patch.rs b/src/patch/patch.rs index 230c5bf..26441f8 100644 --- a/src/patch/patch.rs +++ b/src/patch/patch.rs @@ -395,18 +395,18 @@ pub struct PatchConfig { pub fn load_config() -> PatchConfig { let ini_file = match fs::File::open(std::path::Path::new("patch.ron")) { - Err(err) => panic!("Failed to open patch.ron config file. \n{}", err), + Err(err) => panic!("Failed to open patch.ron config file. \n{err}"), Ok(ini_file) => ini_file, }; let mut s = String::new(); if let Err(err) = (&ini_file).read_to_string(&mut s) { - panic!("Failed to read patch.ron config file. \n{}", err); + panic!("Failed to read patch.ron config file. \n{err}"); } let config: PatchConfig = match from_str(s.as_str()) { Ok(config) => config, - Err(err) => panic!("Failed to load values from patch.ron \n{}",err), + Err(err) => panic!("Failed to load values from patch.ron \n{err}"), }; config } diff --git a/src/ship/drops/mod.rs b/src/ship/drops/mod.rs index 9c20130..5d8062c 100644 --- a/src/ship/drops/mod.rs +++ b/src/ship/drops/mod.rs @@ -257,7 +257,7 @@ impl DropTableBuilder { unit_table: self.unit_table.unwrap_or_else(|| GenericUnitTable::new(episode, difficulty, section_id)), tool_table: self.tool_table.unwrap_or_else(|| ToolTable::new(episode, difficulty, section_id)), box_table: self.box_table.unwrap_or_else(|| BoxDropTable::new(episode, difficulty, section_id)), - rng: self.rng.unwrap_or_else(|| rand_chacha::ChaCha20Rng::from_entropy()), + rng: self.rng.unwrap_or_else(rand_chacha::ChaCha20Rng::from_entropy), } } } diff --git a/src/ship/items/apply_item.rs b/src/ship/items/apply_item.rs index 5534b47..9820226 100644 --- a/src/ship/items/apply_item.rs +++ b/src/ship/items/apply_item.rs @@ -8,9 +8,9 @@ use crate::entity::gateway::{EntityGateway, GatewayError}; use crate::entity::character::{CharacterEntity, TechLevel}; use crate::entity::item::mag::{MagCell, MagCellError}; use crate::entity::item::tool::{Tool, ToolType}; -use crate::entity::item::tech::{TechniqueDisk, Technique}; +use crate::entity::item::tech::TechniqueDisk; use crate::entity::item::{ItemDetail, ItemEntityId}; -use crate::ship::items::state::{ItemStateProxy, ItemStateError}; +use crate::ship::items::state::ItemStateProxy; use crate::ship::items::inventory::{InventoryItem, InventoryItemDetail}; @@ -26,10 +26,6 @@ pub enum ApplyItemError { InvalidTool, #[error("gateway error {0}")] GatewayError(#[from] GatewayError), - - //#[error("itemstate error {0}")] - //ItemStateError(Box), - #[error("magcell error {0}")] MagCellError(#[from] MagCellError), } @@ -42,15 +38,6 @@ pub enum ApplyItemAction { //RemoveItem, } -/* -impl From for ApplyItemError { - fn from(other: ItemStateError) -> ApplyItemError { - ApplyItemError::ItemStateError(Box::new(other)) - } -} -*/ - - async fn power_material(entity_gateway: &mut EG, character: &mut CharacterEntity) -> Result, anyhow::Error> { character.materials.power += 1; entity_gateway.save_character(character).await?; @@ -315,14 +302,14 @@ where // TODO: rest of these _ => Err(anyhow::Error::from(ApplyItemError::InvalidTool)) .with_context(|| { - format!("invalid tool {:?}", tool) + format!("invalid tool {tool:?}") }) } } -async fn apply_tech<'a, EG>(item_state: &mut ItemStateProxy, +async fn apply_tech<'a, EG>(_item_state: &mut ItemStateProxy, entity_gateway: &mut EG, character: &mut CharacterEntity, _entity_id: ItemEntityId, @@ -353,7 +340,7 @@ where ItemDetail::TechniqueDisk(tech) => apply_tech(item_state, entity_gateway, character, individual_item.entity_id, tech).await, _ => Err(anyhow::Error::from(ApplyItemError::InvalidItem)) .with_context(|| { - format!("item {:?}", individual_item) + format!("item {individual_item:?}") }) } }, diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index 1267b1b..a166d8b 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -372,7 +372,7 @@ impl ItemState { .map(|item| (item.clone(), FloorType::Shared)) }) .ok_or_else(|| ItemStateError::NoFloorItem(*item_id)) - .with_context(|| format!("character {}\nlocal floors: {:#?}\nshared floors: {:#?}", character_id, local_floors, shared_floors)) + .with_context(|| format!("character {character_id}\nlocal floors: {local_floors:#?}\nshared floors: {shared_floors:#?}")) } } diff --git a/src/ship/map/enemy.rs b/src/ship/map/enemy.rs index 96e63cb..4989041 100644 --- a/src/ship/map/enemy.rs +++ b/src/ship/map/enemy.rs @@ -103,7 +103,7 @@ impl RareMonsterAppearTable { rand_chacha::ChaChaRng::from_entropy().gen::() < *self.appear_rate.get(monster).unwrap_or(&0.0f32) } - pub fn apply(&self, mut enemy: MapEnemy, event: ShipEvent) -> MapEnemy { + pub fn apply(&self, enemy: MapEnemy, event: ShipEvent) -> MapEnemy { if enemy.can_be_rare() && self.roll_is_rare(&enemy.monster) { enemy.into_rare(event) } diff --git a/src/ship/packet/handler/room.rs b/src/ship/packet/handler/room.rs index 0a108ca..4cdf611 100644 --- a/src/ship/packet/handler/room.rs +++ b/src/ship/packet/handler/room.rs @@ -16,6 +16,7 @@ use crate::ship::location::{ClientLocation, RoomId, RoomLobby, GetAreaError}; use crate::ship::packet::builder; use crate::ship::items::state::ItemState; +#[allow(clippy::too_many_arguments)] pub async fn create_room(id: ClientId, create_room: CreateRoom, client_location: &mut ClientLocation, diff --git a/src/ship/packet/handler/settings.rs b/src/ship/packet/handler/settings.rs index 3566b69..b40da3c 100644 --- a/src/ship/packet/handler/settings.rs +++ b/src/ship/packet/handler/settings.rs @@ -1,6 +1,6 @@ use libpso::packet::ship::*; use crate::common::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, Clients}; +use crate::ship::ship::{SendShipPacket, Clients}; use crate::entity::gateway::EntityGateway; pub async fn update_config(id: ClientId, diff --git a/src/ship/room.rs b/src/ship/room.rs index a48bfc3..87e5585 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -13,12 +13,10 @@ use crate::ship::drops::DropTable; use crate::entity::character::SectionID; use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats}; use crate::ship::map::area::MapAreaLookup; -use crate::ship::map::enemy::RareMonsterAppearTable; use crate::ship::quests; use crate::ship::ship::{ShipError, ShipEvent}; use crate::ship::location::{MAX_ROOMS, RoomId}; - #[derive(Clone)] pub struct Rooms([Arc>>; MAX_ROOMS]); @@ -261,17 +259,11 @@ impl RoomMode { } pub fn battle(&self) -> bool { - match self { - RoomMode::Battle {..} => true, - _ => false, - } + matches!(self, RoomMode::Battle {..}) } pub fn challenge(&self) -> bool { - match self { - RoomMode::Challenge {..} => true, - _ => false, - } + matches!(self, RoomMode::Challenge {..}) } pub fn player_mode(&self) -> PlayerMode { diff --git a/src/ship/ship.rs b/src/ship/ship.rs index fc5581c..1d1bb47 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -2,11 +2,8 @@ use std::net::Ipv4Addr; use std::collections::HashMap; -use std::backtrace::Backtrace; - use async_std::channel; use async_std::sync::{Arc, Mutex, RwLock}; - use rand::Rng; use thiserror::Error; @@ -15,21 +12,15 @@ use libpso::packet::login::{RedirectClient, Login, LoginResponse, ShipList}; use libpso::packet::messages::*; use libpso::{PacketParseError, PSOPacket}; use libpso::crypto::bb::PSOBBCipher; - use libpso::packet::ship::{BLOCK_MENU_ID, ROOM_MENU_ID}; - use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; use crate::common::interserver::{AuthToken, Ship, ServerId, InterserverActor, LoginMessage, ShipMessage}; - use crate::login::character::SHIP_MENU_ID; - use crate::entity::gateway::{EntityGateway, GatewayError}; use crate::entity::character::SectionID; - use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; - use crate::ship::drops::DropTable; use crate::ship::items; use crate::ship::room; @@ -690,12 +681,12 @@ impl ServerState for ShipServerState { let block = self.blocks.get_from_client(id, &self.clients).await?; match menuselect.menu { SHIP_MENU_ID => { - let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().into_iter().flatten(); + let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); let select_ship = handler::ship::selected_ship(id, menuselect, &self.ship_list).await?; leave_lobby.chain(select_ship).collect() } BLOCK_MENU_ID => { - let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().into_iter().flatten(); + let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter(); leave_lobby.chain(select_block).collect() }