Fix clippy warnings

master
Elnu 2 years ago
parent 4e9784baf4
commit 8427eb082b

@ -2,8 +2,7 @@ use wana_kana::{ConvertJapanese, IsJapaneseStr};
pub fn lookup(input: &str) -> Option<&jisho::Entry> { pub fn lookup(input: &str) -> Option<&jisho::Entry> {
let input = input.trim(); let input = input.trim();
for word in jisho::lookup(input) { jisho::lookup(input).into_iter().find(|&word| (
if
// If input has no kanji, // If input has no kanji,
// we can just compare the input to the reading verbatim // we can just compare the input to the reading verbatim
// ensuring both are hiragana // ensuring both are hiragana
@ -12,9 +11,5 @@ pub fn lookup(input: &str) -> Option<&jisho::Entry> {
// is verbosely the same. // is verbosely the same.
// However, this will cause problems for some words. // However, this will cause problems for some words.
// For example, 照り焼き will be accepted but 照焼 won't. // For example, 照り焼き will be accepted but 照焼 won't.
(input == word.kanji) { (input == word.kanji)))
return Some(word);
}
}
return None;
} }

@ -13,6 +13,6 @@ pub use word::*;
fn main() { fn main() {
const PORT: u16 = 8080; const PORT: u16 = 8080;
let mut server = Server::new(PORT) 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(); server.run();
} }

@ -47,15 +47,15 @@ impl MessageResponseData {
}) })
} }
fn to_response(self) -> MessageResponse { fn into_response(self) -> MessageResponse {
MessageResponse { MessageResponse {
event: self.get_name(), event: self.get_name(),
data: self, data: self,
} }
} }
fn to_message(self) -> Message { fn into_message(self) -> Message {
self.to_response().to_message() self.into_response().to_message()
} }
} }
@ -89,7 +89,7 @@ impl Server {
} }
fn broadcast_player_count(&self) { 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() { for (_client, responder) in self.clients.iter() {
responder.send(response.to_message()); responder.send(response.to_message());
} }
@ -97,7 +97,7 @@ impl Server {
fn handle_connection(&mut self, client_id: u64, responder: Responder) { fn handle_connection(&mut self, client_id: u64, responder: Responder) {
println!("A client connected with id #{}", client_id); 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 { if let Some(ref last_response) = self.last_response {
responder.send(last_response.to_message()); responder.send(last_response.to_message());
} }
@ -160,7 +160,7 @@ impl Server {
message: String::from("Not in dictionary!"), message: String::from("Not in dictionary!"),
}, },
} }
}.to_response(); }.into_response();
match response.data { match response.data {
// Send errors to only this client // Send errors to only this client

Loading…
Cancel
Save