Browse Source

refactor: replace static with const for global constants (#494)

Integral 1 year ago
parent
commit
772db7422f
3 changed files with 6 additions and 6 deletions
  1. 1 1
      libs/hbb_common/src/keyboard.rs
  2. 4 4
      src/peer.rs
  3. 1 1
      src/rendezvous_server.rs

+ 1 - 1
libs/hbb_common/src/keyboard.rs

@@ -28,7 +28,7 @@ impl FromStr for KeyboardMode {
28 28
 
29 29
 impl KeyboardMode {
30 30
     pub fn iter() -> Iter<'static, KeyboardMode> {
31
-        static KEYBOARD_MODES: [KeyboardMode; 4] = [
31
+        const KEYBOARD_MODES: [KeyboardMode; 4] = [
32 32
             KeyboardMode::Legacy,
33 33
             KeyboardMode::Map,
34 34
             KeyboardMode::Translate,

+ 4 - 4
src/peer.rs

@@ -18,10 +18,10 @@ lazy_static::lazy_static! {
18 18
     pub(crate) static ref USER_STATUS: RwLock<UserStatusMap> = Default::default();
19 19
     pub(crate) static ref IP_CHANGES: Mutex<IpChangesMap> = Default::default();
20 20
 }
21
-pub static IP_CHANGE_DUR: u64 = 180;
22
-pub static IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2;
23
-pub static DAY_SECONDS: u64 = 3600 * 24;
24
-pub static IP_BLOCK_DUR: u64 = 60;
21
+pub const IP_CHANGE_DUR: u64 = 180;
22
+pub const IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2;
23
+pub const DAY_SECONDS: u64 = 3600 * 24;
24
+pub const IP_BLOCK_DUR: u64 = 60;
25 25
 
26 26
 #[derive(Debug, Default, Serialize, Deserialize, Clone)]
27 27
 pub(crate) struct PeerInfo {

+ 1 - 1
src/rendezvous_server.rs

@@ -58,7 +58,7 @@ type Sender = mpsc::UnboundedSender<Data>;
58 58
 type Receiver = mpsc::UnboundedReceiver<Data>;
59 59
 static ROTATION_RELAY_SERVER: AtomicUsize = AtomicUsize::new(0);
60 60
 type RelayServers = Vec<String>;
61
-static CHECK_RELAY_TIMEOUT: u64 = 3_000;
61
+const CHECK_RELAY_TIMEOUT: u64 = 3_000;
62 62
 static ALWAYS_USE_RELAY: AtomicBool = AtomicBool::new(false);
63 63
 
64 64
 #[derive(Clone)]