From 486abbd9f733ba0c6f8baef0cd38252f54c66fcf Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 11 Dec 2023 03:45:54 +0200 Subject: [PATCH] chore: use Self where possible --- crates/lib/src/protocols/types.rs | 12 ++++++------ crates/lib/src/protocols/unreal2/types.rs | 6 +++--- crates/lib/src/protocols/valve/types.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/lib/src/protocols/types.rs b/crates/lib/src/protocols/types.rs index 9bd4b53..cb01517 100644 --- a/crates/lib/src/protocols/types.rs +++ b/crates/lib/src/protocols/types.rs @@ -231,33 +231,33 @@ impl TimeoutSettings { /// Get the number of retries if there are timeout settings else fall back /// to the default - pub const fn get_retries_or_default(timeout_settings: &Option) -> usize { + pub const fn get_retries_or_default(timeout_settings: &Option) -> usize { if let Some(timeout_settings) = timeout_settings { timeout_settings.get_retries() } else { - TimeoutSettings::const_default().get_retries() + Self::const_default().get_retries() } } /// Get the read and write durations if there are timeout settings else fall /// back to the defaults pub const fn get_read_and_write_or_defaults( - timeout_settings: &Option, + timeout_settings: &Option, ) -> (Option, Option) { if let Some(timeout_settings) = timeout_settings { (timeout_settings.get_read(), timeout_settings.get_write()) } else { - let default = TimeoutSettings::const_default(); + let default = Self::const_default(); (default.get_read(), default.get_write()) } } /// Get the connect duration given timeout settings or get the default. - pub const fn get_connect_or_default(timeout_settings: &Option) -> Option { + pub const fn get_connect_or_default(timeout_settings: &Option) -> Option { if let Some(timeout_settings) = timeout_settings { timeout_settings.get_connect() } else { - TimeoutSettings::const_default().get_connect() + Self::const_default().get_connect() } } diff --git a/crates/lib/src/protocols/unreal2/types.rs b/crates/lib/src/protocols/unreal2/types.rs index 468e9e8..bab95c0 100644 --- a/crates/lib/src/protocols/unreal2/types.rs +++ b/crates/lib/src/protocols/unreal2/types.rs @@ -50,7 +50,7 @@ pub struct ServerInfo { impl ServerInfo { pub fn parse(buffer: &mut Buffer) -> GDResult { - Ok(ServerInfo { + Ok(Self { server_id: buffer.read()?, ip: buffer.read_string::(None)?, game_port: buffer.read()?, @@ -118,7 +118,7 @@ impl Players { /// Pre-allocate the vectors inside the players struct based on the provided /// capacity. pub fn with_capacity(capacity: usize) -> Self { - Players { + Self { players: Vec::with_capacity(capacity), // Allocate half as many bots as we don't expect there to be as many bots: Vec::with_capacity(capacity / 2), @@ -234,7 +234,7 @@ impl GatheringSettings { } impl Default for GatheringSettings { - fn default() -> Self { GatheringSettings::default() } + fn default() -> Self { Self::default() } } impl From for GatheringSettings { diff --git a/crates/lib/src/protocols/valve/types.rs b/crates/lib/src/protocols/valve/types.rs index ebe46ad..b0d9b92 100644 --- a/crates/lib/src/protocols/valve/types.rs +++ b/crates/lib/src/protocols/valve/types.rs @@ -310,7 +310,7 @@ impl GatheringSettings { } impl Default for GatheringSettings { - fn default() -> Self { GatheringSettings::default() } + fn default() -> Self { Self::default() } } impl From for GatheringSettings {