Skip to content

Commit 45760ee

Browse files
committed
LazyLock usage
1 parent 3864448 commit 45760ee

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ license = "MIT"
66
description = "A simple proxy tunnel, minimalist tool for bypassing the GFW."
77
repository = "https://github.com/ShadowsocksR-Live/overtls"
88
readme = "readme.md"
9+
rust-version = "1.80"
910

1011
[lib]
1112
crate-type = ["staticlib", "cdylib", "lib"]
@@ -26,7 +27,6 @@ futures-util = { version = "0.3", default-features = false, features = [
2627
hickory-proto = "0.24"
2728
http = "1"
2829
httparse = "1"
29-
lazy_static = "1"
3030
log = { version = "0.4", features = ["std"] }
3131
moka = { version = "0.12", default-features = false, features = ["future"] }
3232
reqwest = { version = "0.12", default-features = false, features = [

src/traffic_status.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::error::{Error, Result};
2-
use std::{os::raw::c_void, sync::Mutex};
2+
use std::{
3+
os::raw::c_void,
4+
sync::{LazyLock, Mutex},
5+
};
36

47
/// # Safety
58
///
@@ -44,10 +47,8 @@ unsafe impl Sync for TrafficStatusCallback {}
4447
static TRAFFIC_STATUS_CALLBACK: Mutex<Option<TrafficStatusCallback>> = Mutex::new(None);
4548
static SEND_INTERVAL_SECS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
4649

47-
lazy_static::lazy_static! {
48-
static ref TRAFFIC_STATUS: Mutex<TrafficStatus> = Mutex::new(TrafficStatus::default());
49-
static ref TIME_STAMP: Mutex<std::time::Instant> = Mutex::new(std::time::Instant::now());
50-
}
50+
static TRAFFIC_STATUS: LazyLock<Mutex<TrafficStatus>> = LazyLock::new(|| Mutex::new(TrafficStatus::default()));
51+
static TIME_STAMP: LazyLock<Mutex<std::time::Instant>> = LazyLock::new(|| Mutex::new(std::time::Instant::now()));
5152

5253
pub(crate) fn traffic_status_update(delta_tx: usize, delta_rx: usize) -> Result<()> {
5354
{

0 commit comments

Comments
 (0)