diff options
| -rw-r--r-- | crates/whirl/src/cli.rs | 12 | ||||
| -rw-r--r-- | crates/whirl/src/lib.rs | 3 | ||||
| -rw-r--r-- | crates/whirl_api/src/lib.rs | 3 | ||||
| -rw-r--r-- | crates/whirl_api/src/routes/worlds/info/mod.rs | 2 | ||||
| -rw-r--r-- | crates/whirl_common/src/log.rs | 2 | ||||
| -rw-r--r-- | crates/whirl_common/src/sort.rs | 4 | ||||
| -rw-r--r-- | crates/whirl_prompt/src/builtins/mod.rs | 16 | ||||
| -rw-r--r-- | crates/whirl_prompt/src/lib.rs | 12 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/appear_actor.rs | 4 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/register_object_id.rs | 2 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/structure.rs | 6 | ||||
| -rw-r--r-- | crates/whirl_server/src/distributor.rs | 10 | ||||
| -rw-r--r-- | crates/whirl_server/src/hub.rs | 8 | ||||
| -rw-r--r-- | crates/whirl_server/src/interaction/shared.rs | 1 | ||||
| -rw-r--r-- | crates/whirl_server/src/lib.rs | 18 | ||||
| -rw-r--r-- | crates/whirl_server/src/net/network_property.rs | 5 | ||||
| -rw-r--r-- | crates/whirl_server/src/packet_parser.rs | 4 |
17 files changed, 58 insertions, 54 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs index bd0caa3..e9b6f07 100644 --- a/crates/whirl/src/cli.rs +++ b/crates/whirl/src/cli.rs @@ -62,7 +62,7 @@ impl Cli { debug!("attempting to create .whirl directory..."); match std::fs::create_dir(".whirl/") { - Ok(_) => debug!("successfully created .whirl directory"), + Ok(()) => debug!("successfully created .whirl directory"), Err(e) => debug!("error creating .whirl directory: {}", e), } @@ -74,11 +74,10 @@ impl Cli { // pass any sub-server types meaning that the subcommand `run` was // called without any arguments, in other words: "run everything". let mut types = { - // s_matches.values_of("type").unwrap().collect::<Vec<_>>(); - match s_matches.values_of("type") { - Some(values) => values.collect::<Vec<_>>(), - None => vec!["distributor", "hub", "api"], - } + s_matches.values_of("type").map_or_else( + || vec!["distributor", "hub", "api"], + std::iter::Iterator::collect, + ) }; // Remove any duplicate sub-commands, we don't want to start two // instances of the same sub-server. @@ -183,6 +182,7 @@ impl Cli { } async fn run(mut server_type: Vec<RunType>) { + #[allow(clippy::collection_is_never_read)] let mut threads = vec![]; // Iterate over all of of the requested sub-servers and spawn one of each. while let Some(run_type) = server_type.last() { diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs index 3bdbe0d..6b9dd96 100644 --- a/crates/whirl/src/lib.rs +++ b/crates/whirl/src/lib.rs @@ -75,8 +75,9 @@ impl Whirl { // Ctrl+C handling #[cfg(unix)] + #[allow(clippy::never_loop)] tokio::spawn(async move { - for signal in signal_hook::iterator::Signals::new(&[SIGTERM, SIGINT]) + for signal in signal_hook::iterator::Signals::new([SIGTERM, SIGINT]) .unwrap() .forever() { diff --git a/crates/whirl_api/src/lib.rs b/crates/whirl_api/src/lib.rs index 589fda0..24b8136 100644 --- a/crates/whirl_api/src/lib.rs +++ b/crates/whirl_api/src/lib.rs @@ -18,6 +18,7 @@ html_logo_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png", html_favicon_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png" )] +#![allow(clippy::cast_precision_loss)] #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; @@ -63,7 +64,7 @@ impl Api { #[must_use] pub fn make() -> tokio::task::JoinHandle<()> { tokio::spawn(async move { - crate::Api::listen(&*format!( + crate::Api::listen(&format!( "{}:{}", whirl_config::Config::get().whirlsplash.ip, whirl_config::Config::get().whirlsplash.api.port diff --git a/crates/whirl_api/src/routes/worlds/info/mod.rs b/crates/whirl_api/src/routes/worlds/info/mod.rs index 382c07f..a9d098a 100644 --- a/crates/whirl_api/src/routes/worlds/info/mod.rs +++ b/crates/whirl_api/src/routes/worlds/info/mod.rs @@ -15,7 +15,7 @@ pub async fn info( easy .url(&format!( "http://www-dynamic.us.worlds.net/cgi-bin/profile.pl?{}", - req.username.as_ref().unwrap_or(&"".to_string()), + req.username.as_ref().unwrap_or(&String::new()), )) .unwrap(); diff --git a/crates/whirl_common/src/log.rs b/crates/whirl_common/src/log.rs index 38248cf..98aba50 100644 --- a/crates/whirl_common/src/log.rs +++ b/crates/whirl_common/src/log.rs @@ -15,7 +15,7 @@ pub fn calculate_log_level() -> String { _ => "info".to_string(), }; if !Config::get().whirlsplash.log.everything { - level = format!("whirl={}", level); + level = format!("whirl={level}"); } level diff --git a/crates/whirl_common/src/sort.rs b/crates/whirl_common/src/sort.rs index 9c7e092..c8b9cae 100644 --- a/crates/whirl_common/src/sort.rs +++ b/crates/whirl_common/src/sort.rs @@ -3,6 +3,6 @@ /// Sort a vector by alphabetical order based on the first character of each /// string. -pub fn vec_alphabetically(vec: &mut Vec<&str>) { - vec.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase())); +pub fn vec_alphabetically(vec: &mut [&str]) { + vec.sort_by_key(|a| a.to_lowercase()); } diff --git a/crates/whirl_prompt/src/builtins/mod.rs b/crates/whirl_prompt/src/builtins/mod.rs index b7f98b3..ed13f87 100644 --- a/crates/whirl_prompt/src/builtins/mod.rs +++ b/crates/whirl_prompt/src/builtins/mod.rs @@ -28,7 +28,7 @@ pub fn builtin_history(history: &[String]) -> i32 { pub fn builtin_help() -> i32 { for help in &HELPABLES_BUILTINS { - println!("{}", help); + println!("{help}"); } 0 @@ -36,7 +36,7 @@ pub fn builtin_help() -> i32 { pub fn builtin_ls() -> i32 { for file in &FILES { - print!("{} ", file); + print!("{file} "); } println!(); @@ -45,7 +45,7 @@ pub fn builtin_ls() -> i32 { pub fn builtin_cat(args: &[String]) -> i32 { let file; - if let Some(file_name) = args.get(0) { + if let Some(file_name) = args.first() { file = file_name.to_string(); } else { return 0; @@ -72,19 +72,19 @@ pub fn builtin_cat(args: &[String]) -> i32 { colour::red_ln!("NOTE: This is just a wrapper for `config show`."); println!("{:#?}", Config::get()); } - _ => println!("/cat: {}: no such file or directory", file), + _ => println!("/cat: {file}: no such file or directory"), } 0 } pub fn builtin_config(args: &[String]) -> i32 { - match args.get(0) { + match args.first() { Some(sub) => match sub.as_str() { "show" => println!("{:#?}", Config::get()), "help" | "--help" | "-h" => for help in &HELPABLES_BUILTIN_CONFIG { - println!("{}", help); + println!("{help}"); }, // "refresh" => Config::refresh(), _ => println!("invalid arguments provided"), @@ -102,12 +102,12 @@ pub fn builtin_fetch(args: &[String]) -> i32 { let mut whirl_image = false; #[allow(clippy::single_match)] - match args.get(0) { + match args.first() { Some(sub) => match sub.as_str() { "--whirl" | "-w" => whirl_image = true, "help" | "--help" | "-h" => { for help in &HELPABLES_BUILTIN_FETCH { - println!("{}", help); + println!("{help}"); } return 0; } diff --git a/crates/whirl_prompt/src/lib.rs b/crates/whirl_prompt/src/lib.rs index 692282f..fc77faa 100644 --- a/crates/whirl_prompt/src/lib.rs +++ b/crates/whirl_prompt/src/lib.rs @@ -45,6 +45,7 @@ pub struct Prompt { } impl Prompt { /// Begin handling user input as the prompt. + #[allow(clippy::unused_async)] pub async fn handle() -> ! { let mut prompt = Self { history: vec![] }; @@ -118,7 +119,7 @@ mod tokenize_command { #[test] fn test_keyword() { - assert_eq!("test", Prompt::tokenize_command("test").keyword) + assert_eq!("test", Prompt::tokenize_command("test").keyword); } #[test] @@ -126,17 +127,20 @@ mod tokenize_command { #[test] fn one_arg() { - assert_eq!(1, Prompt::tokenize_command("test one").args.len()) + assert_eq!(1, Prompt::tokenize_command("test one").args.len()); } #[test] fn multi_arg() { - assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()) + assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()); } #[test] #[ignore] fn quotes() { - assert_eq!(2, Prompt::tokenize_command("test \"one two\" three").args.len()) + assert_eq!( + 2, + Prompt::tokenize_command("test \"one two\" three").args.len() + ); } } diff --git a/crates/whirl_server/src/cmd/commands/appear_actor.rs b/crates/whirl_server/src/cmd/commands/appear_actor.rs index 836c681..6100fcc 100644 --- a/crates/whirl_server/src/cmd/commands/appear_actor.rs +++ b/crates/whirl_server/src/cmd/commands/appear_actor.rs @@ -25,8 +25,8 @@ impl Creatable for AppearActor { command.put_i8(Command::ApprActr as i32 as i8); // Type // Content - command.put_i8(self.short_object_id as i8); // ObjId, why is it here? Worlds... - command.put_u16(self.room_id as u16); // Room ID + command.put_i8(self.short_object_id); // ObjId, why is it here? Worlds... + command.put_u16(self.room_id); // Room ID command.put_u16(self.x as u16); // X command.put_u16(self.y as u16); // Y command.put_u16(self.z as u16); // Z diff --git a/crates/whirl_server/src/cmd/commands/register_object_id.rs b/crates/whirl_server/src/cmd/commands/register_object_id.rs index 7791ae2..bdf4bca 100644 --- a/crates/whirl_server/src/cmd/commands/register_object_id.rs +++ b/crates/whirl_server/src/cmd/commands/register_object_id.rs @@ -23,7 +23,7 @@ impl Creatable for RegisterObjectId { // Content command.put_u8(self.long_object_id.len() as u8); // Long object ID length command.put_slice(self.long_object_id.as_bytes()); // Long object ID - command.put_i8(self.short_object_id as i8); // Short object ID + command.put_i8(self.short_object_id); // Short object ID // Length let mut command_as_vec = command.to_vec(); diff --git a/crates/whirl_server/src/cmd/structure.rs b/crates/whirl_server/src/cmd/structure.rs index 54d47ed..de6567e 100644 --- a/crates/whirl_server/src/cmd/structure.rs +++ b/crates/whirl_server/src/cmd/structure.rs @@ -1,6 +1,7 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only +#[derive(Default)] pub struct Command { pub length: i32, pub obj_id: i32, @@ -32,7 +33,7 @@ impl Command { body: vec![], }; if command.length > 3 { - command.body = data[3..].to_owned(); + data[3..].clone_into(&mut command.body); } command_set.push(command); @@ -44,6 +45,3 @@ impl Command { command_set } } -impl Default for Command { - fn default() -> Self { Self { length: 0, obj_id: 0, id: 0, body: vec![] } } -} diff --git a/crates/whirl_server/src/distributor.rs b/crates/whirl_server/src/distributor.rs index cf9acbf..e89b8d8 100644 --- a/crates/whirl_server/src/distributor.rs +++ b/crates/whirl_server/src/distributor.rs @@ -67,7 +67,7 @@ impl Server for Distributor { result = peer.bytes.next() => match result { Some(Ok(msg)) => { for msg in parse_commands_from_packet(msg) { - match num_traits::FromPrimitive::from_i32(msg.get(2).unwrap().to_owned() as i32) { + match num_traits::FromPrimitive::from_i32(i32::from(msg.get(2).unwrap().to_owned())) { Some(Command::PropReq) => { debug!("received property request from client"); @@ -76,9 +76,9 @@ impl Server for Distributor { trace!("sent property update to client"); } Some(Command::SessInit) => { - username = (*crate::net::property_list::PropertyList::from_bytes(msg[3..] + username = crate::net::property_list::PropertyList::from_bytes(msg[3..] .to_vec()) - .find(VAR_USERNAME)).value.to_string(); + .find(VAR_USERNAME).value.to_string(); debug!("received session initialization from {}", username); @@ -114,13 +114,13 @@ impl Server for Distributor { trace!("found room: {}", room.room_name); room_id = position; } else { - room_ids.push((&*room.room_name).to_string()); + room_ids.push((*room.room_name).to_string()); room_id = room_ids.iter().position(|r| r == &room.room_name).unwrap(); trace!("inserted room {}: {}", room.room_name, room_id); } peer.bytes.get_mut().write_all(&RedirectId { - room_name: (&*room.room_name).to_string(), + room_name: (*room.room_name).to_string(), room_number: room_id as i8, }.create()).await?; trace!("sent redirect id to {}: {}", username, room.room_name); diff --git a/crates/whirl_server/src/hub.rs b/crates/whirl_server/src/hub.rs index af4e656..f1a8120 100644 --- a/crates/whirl_server/src/hub.rs +++ b/crates/whirl_server/src/hub.rs @@ -70,7 +70,7 @@ impl Server for Hub { Some(Ok(msg)) => { // trace!("got some bytes: {:?}", &msg); for msg in parse_commands_from_packet(msg) { - match num_traits::FromPrimitive::from_i32(msg.get(2).unwrap().to_owned() as i32) { + match num_traits::FromPrimitive::from_i32(i32::from(msg.get(2).unwrap().to_owned())) { Some(Command::PropReq) => { debug!("received property request from client"); @@ -79,9 +79,9 @@ impl Server for Hub { trace!("sent property update to client"); } Some(Command::SessInit) => { - username = (*crate::net::property_list::PropertyList::from_bytes(msg[3..] + username = crate::net::property_list::PropertyList::from_bytes(msg[3..] .to_vec()) - .find(VAR_USERNAME)).value.to_string(); + .find(VAR_USERNAME).value.to_string(); debug!("received session initialization from {}", username); @@ -142,7 +142,7 @@ impl Server for Hub { { state.lock().await.broadcast(&Text { - sender: (&*username).to_string(), + sender: (*username).to_string(), content: text.content.clone(), }.create()).await; } diff --git a/crates/whirl_server/src/interaction/shared.rs b/crates/whirl_server/src/interaction/shared.rs index fc8674e..4e1d158 100644 --- a/crates/whirl_server/src/interaction/shared.rs +++ b/crates/whirl_server/src/interaction/shared.rs @@ -9,6 +9,7 @@ pub struct Shared { impl Shared { pub fn new() -> Self { Self { peers: HashMap::new() } } + #[allow(clippy::unused_async)] pub async fn broadcast(&mut self, message: &[u8]) { for peer in &mut self.peers { peer.1.send(BytesMut::from(message)).unwrap(); diff --git a/crates/whirl_server/src/lib.rs b/crates/whirl_server/src/lib.rs index e8fdb6f..410522b 100644 --- a/crates/whirl_server/src/lib.rs +++ b/crates/whirl_server/src/lib.rs @@ -18,7 +18,13 @@ html_logo_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png", html_favicon_url = "https://raw.githubusercontent.com/Whirlsplash/assets/master/Whirl.png" )] -#![allow(non_local_definitions, dead_code)] +#![allow( + non_local_definitions, + dead_code, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::cast_possible_wrap +)] #[macro_use] extern crate log; #[macro_use] extern crate async_trait; @@ -53,7 +59,7 @@ pub enum ServerType { // https://stackoverflow.com/a/32712140/14452787 impl fmt::Display for ServerType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } @@ -123,7 +129,7 @@ pub mod make { pub fn distributor() -> JoinHandle<()> { tokio::spawn(async move { crate::distributor::Distributor::listen( - &*format!( + &format!( "{}:{}", Config::get().whirlsplash.ip, Config::get().distributor.port @@ -144,11 +150,7 @@ pub mod make { pub fn hub() -> JoinHandle<()> { tokio::spawn(async move { crate::hub::Hub::listen( - &*format!( - "{}:{}", - Config::get().whirlsplash.ip, - Config::get().hub.port - ), + &format!("{}:{}", Config::get().whirlsplash.ip, Config::get().hub.port), ServerType::Room, ) .await diff --git a/crates/whirl_server/src/net/network_property.rs b/crates/whirl_server/src/net/network_property.rs index ef793bc..390412e 100644 --- a/crates/whirl_server/src/net/network_property.rs +++ b/crates/whirl_server/src/net/network_property.rs @@ -1,7 +1,7 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -#[derive(Clone)] +#[derive(Clone, Default)] pub struct NetworkProperty { pub prop_id: i32, pub value: String, @@ -9,6 +9,3 @@ pub struct NetworkProperty { impl NetworkProperty { pub fn _new() -> Self { Self::default() } } -impl Default for NetworkProperty { - fn default() -> Self { Self { prop_id: 0, value: "".to_string() } } -} diff --git a/crates/whirl_server/src/packet_parser.rs b/crates/whirl_server/src/packet_parser.rs index 13e9d0c..e0da32d 100644 --- a/crates/whirl_server/src/packet_parser.rs +++ b/crates/whirl_server/src/packet_parser.rs @@ -14,11 +14,11 @@ pub fn parse_commands_from_packet(mut buffer: BytesMut) -> Vec<BytesMut> { let mut commands: Vec<BytesMut> = Vec::new(); trace!("initial buffer: {:?}, length: {}", buffer, buffer.len()); - let data_length = buffer.get(0).unwrap().to_owned() as usize; + let data_length = buffer.first().unwrap().to_owned() as usize; if buffer.len() > data_length { loop { trace!("loop: {:?}, length: {}", buffer, buffer.len()); - let command_length = buffer.get(0).unwrap().to_owned() as usize; + let command_length = buffer.first().unwrap().to_owned() as usize; commands.push(BytesMut::from(buffer.get(0..command_length).unwrap())); // Remove command from buffer |