From 8427eb082bddc483e4b9aed9837eb2090726d605 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Fri, 14 Apr 2023 13:24:21 -0700 Subject: [PATCH] Fix clippy warnings --- src/dictionary.rs | 9 ++------- src/main.rs | 2 +- src/server.rs | 12 ++++++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/dictionary.rs b/src/dictionary.rs index f69bfff..6399e6c 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -2,8 +2,7 @@ use wana_kana::{ConvertJapanese, IsJapaneseStr}; pub fn lookup(input: &str) -> Option<&jisho::Entry> { let input = input.trim(); - for word in jisho::lookup(input) { - if + jisho::lookup(input).into_iter().find(|&word| ( // If input has no kanji, // we can just compare the input to the reading verbatim // ensuring both are hiragana @@ -12,9 +11,5 @@ pub fn lookup(input: &str) -> Option<&jisho::Entry> { // is verbosely the same. // However, this will cause problems for some words. // For example, 照り焼き will be accepted but 照焼 won't. - (input == word.kanji) { - return Some(word); - } - } - return None; + (input == word.kanji))) } diff --git a/src/main.rs b/src/main.rs index 01dc3f7..b51f3f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,6 @@ pub use word::*; fn main() { const PORT: u16 = 8080; let mut server = Server::new(PORT) - .expect(&format!("Failed to start server at port {PORT}")); + .unwrap_or_else(|_| panic!("Failed to start server at port {PORT}")); server.run(); } diff --git a/src/server.rs b/src/server.rs index 27fa31e..f7efebb 100644 --- a/src/server.rs +++ b/src/server.rs @@ -47,15 +47,15 @@ impl MessageResponseData { }) } - fn to_response(self) -> MessageResponse { + fn into_response(self) -> MessageResponse { MessageResponse { event: self.get_name(), data: self, } } - fn to_message(self) -> Message { - self.to_response().to_message() + fn into_message(self) -> Message { + self.into_response().to_message() } } @@ -89,7 +89,7 @@ impl Server { } fn broadcast_player_count(&self) { - let response = MessageResponseData::PlayerCount { players: self.clients.len() as u64 }.to_response(); + let response = MessageResponseData::PlayerCount { players: self.clients.len() as u64 }.into_response(); for (_client, responder) in self.clients.iter() { responder.send(response.to_message()); } @@ -97,7 +97,7 @@ impl Server { fn handle_connection(&mut self, client_id: u64, responder: Responder) { println!("A client connected with id #{}", client_id); - responder.send(MessageResponseData::Greeting { id: client_id }.to_message()); + responder.send(MessageResponseData::Greeting { id: client_id }.into_message()); if let Some(ref last_response) = self.last_response { responder.send(last_response.to_message()); } @@ -160,7 +160,7 @@ impl Server { message: String::from("Not in dictionary!"), }, } - }.to_response(); + }.into_response(); match response.data { // Send errors to only this client