From 772db7422f679db1fa06be1097cd676a73055851 Mon Sep 17 00:00:00 2001 From: Integral Date: Sat, 7 Dec 2024 17:54:53 +0800 Subject: refactor: replace static with const for global constants (#494) --- libs/hbb_common/src/keyboard.rs | 2 +- src/peer.rs | 8 ++++---- src/rendezvous_server.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/hbb_common/src/keyboard.rs b/libs/hbb_common/src/keyboard.rs index 10979f5..224f567 100644 --- a/libs/hbb_common/src/keyboard.rs +++ b/libs/hbb_common/src/keyboard.rs @@ -28,7 +28,7 @@ impl FromStr for KeyboardMode { impl KeyboardMode { pub fn iter() -> Iter<'static, KeyboardMode> { - static KEYBOARD_MODES: [KeyboardMode; 4] = [ + const KEYBOARD_MODES: [KeyboardMode; 4] = [ KeyboardMode::Legacy, KeyboardMode::Map, KeyboardMode::Translate, diff --git a/src/peer.rs b/src/peer.rs index c3bf76c..4ca87cf 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -18,10 +18,10 @@ lazy_static::lazy_static! { pub(crate) static ref USER_STATUS: RwLock = Default::default(); pub(crate) static ref IP_CHANGES: Mutex = Default::default(); } -pub static IP_CHANGE_DUR: u64 = 180; -pub static IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2; -pub static DAY_SECONDS: u64 = 3600 * 24; -pub static IP_BLOCK_DUR: u64 = 60; +pub const IP_CHANGE_DUR: u64 = 180; +pub const IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2; +pub const DAY_SECONDS: u64 = 3600 * 24; +pub const IP_BLOCK_DUR: u64 = 60; #[derive(Debug, Default, Serialize, Deserialize, Clone)] pub(crate) struct PeerInfo { diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 9394731..65c8022 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -58,7 +58,7 @@ type Sender = mpsc::UnboundedSender; type Receiver = mpsc::UnboundedReceiver; static ROTATION_RELAY_SERVER: AtomicUsize = AtomicUsize::new(0); type RelayServers = Vec; -static CHECK_RELAY_TIMEOUT: u64 = 3_000; +const CHECK_RELAY_TIMEOUT: u64 = 3_000; static ALWAYS_USE_RELAY: AtomicBool = AtomicBool::new(false); #[derive(Clone)] -- cgit v1.2.3