Skip to content

Commit b4565b7

Browse files
committed
Use LazyLock instead of lazy_static.
1 parent 0b36842 commit b4565b7

File tree

6 files changed

+14
-32
lines changed

6 files changed

+14
-32
lines changed

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ async-trait = "0.1"
5454
zeroize = {version = "1.8", features = ["zeroize_derive"] }
5555
serde = { version = "1.0", features = ["derive"] }
5656
bytes = "1.10"
57-
lazy_static = "1.5"
5857

5958
[dependencies.toml]
6059
version = "0.8"
6160
default-features = false
62-
features = ["preserve_order", "display", "parse"]
63-
64-
[dev-dependencies]
65-
lazy_static = "1.5"
61+
features = ["preserve_order", "display", "parse"]

src/asynch/dropbox.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use std::io::Read;
1818
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
19-
use std::sync::mpsc;
19+
use std::sync::{LazyLock, mpsc};
2020
use std::sync::{Arc, Mutex};
2121
use std::time::{self, Duration};
2222

@@ -31,7 +31,6 @@ use hyper::server::conn::http1;
3131
use hyper::service::service_fn;
3232
use hyper::{Request, Response};
3333
use hyper_util::rt::{TokioIo, TokioTimer};
34-
use lazy_static::lazy_static;
3534
use log::*;
3635
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
3736
use serde::{Deserialize, Serialize};
@@ -74,9 +73,7 @@ const HTTP_GET_RESPONSE_BODY: &str = r#"
7473
</html>
7574
"#;
7675

77-
lazy_static! {
78-
static ref STOP_SYNCHRONIZATION: Mutex<bool> = Mutex::new(false);
79-
}
76+
static STOP_SYNCHRONIZATION: LazyLock<Mutex<bool>> = LazyLock::new(|| { Mutex::new(false) });
8077

8178
/// A Dropbox synchronizer
8279
#[derive(Clone)]

src/asynch/nextcloud.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
use async_trait::async_trait;
1818
use reqwest::{Body, Client, Request, Response};
19-
use lazy_static::lazy_static;
2019
use tokio::time::sleep;
2120
use std::io::prelude::*;
2221
use std::time::Duration;
2322
use url::Url;
24-
use std::sync::Mutex;
23+
use std::sync::{LazyLock, Mutex};
2524

2625
use http::{Method, StatusCode};
2726
use log::*;
@@ -36,9 +35,7 @@ use crate::errors::RustKeylockError;
3635
use crate::SystemConfiguration;
3736
use crate::{errors, file_handler};
3837

39-
lazy_static! {
40-
static ref STOP_SYNCHRONIZATION: Mutex<bool> = Mutex::new(false);
41-
}
38+
static STOP_SYNCHRONIZATION: LazyLock<Mutex<bool>> = LazyLock::new(|| { Mutex::new(false) });
4239

4340
/// A (Next/Own)cloud synchronizer
4441
#[derive(Clone)]
@@ -781,15 +778,14 @@ mod nextcloud_tests {
781778
use std::io::prelude::*;
782779
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
783780
use std::sync::mpsc::{self, Receiver, SyncSender};
784-
use std::sync::Mutex;
781+
use std::sync::{LazyLock, Mutex};
785782
use std::thread;
786783
use std::time;
787784

788785
use http::StatusCode;
789786
use hyper::service::service_fn;
790787
use hyper::{Request, Response};
791788
use hyper_util::rt::{TokioIo, TokioTimer};
792-
use lazy_static::lazy_static;
793789
use std::convert::Infallible;
794790
use tokio;
795791
use toml;
@@ -800,9 +796,7 @@ mod nextcloud_tests {
800796
use super::super::super::{errors, file_handler, SystemConfiguration};
801797
use super::super::AsyncTask;
802798

803-
lazy_static! {
804-
static ref TXMAP: Mutex<HashMap<String, SyncSender<bool>>> = Mutex::new(HashMap::new());
805-
}
799+
static TXMAP: LazyLock<Mutex<HashMap<String, SyncSender<bool>>>> = LazyLock::new(|| { Mutex::new(HashMap::new()) });
806800

807801
fn get_tx_for(command: &str) -> SyncSender<bool> {
808802
let map = TXMAP.lock().unwrap();

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ extern crate futures;
2727
extern crate http;
2828
extern crate hyper;
2929
extern crate hyper_tls;
30-
#[cfg(test)]
31-
extern crate lazy_static;
3230
extern crate log;
3331
extern crate native_tls;
3432
extern crate openssl_probe;

src/rest_server.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ use hyper::server::conn::http1;
2525
use hyper::service::Service;
2626
use hyper::{body::Incoming as IncomingBody, Request, Response};
2727
use hyper_util::rt::TokioIo;
28-
use lazy_static::lazy_static;
2928
use log::{debug, info, warn};
3029
use rand::{thread_rng, Rng};
3130
use spake2::{Ed25519Group, Identity, Password, Spake2};
3231
use tokio::net::TcpListener;
3332
use tokio::task::JoinHandle;
3433
use url::form_urlencoded;
3534

36-
use std::future::Future;
35+
use std::{future::Future, sync::LazyLock};
3736
use std::net::SocketAddr;
3837
use std::pin::Pin;
3938
use std::sync::{Arc, Mutex};
@@ -47,11 +46,9 @@ use crate::{
4746
Entry, Safe,
4847
};
4948

50-
lazy_static! {
51-
static ref SESSION_KEY: Mutex<Option<Vec<u8>>> = Mutex::new(None);
52-
static ref COUNTER: Mutex<Counter> = Mutex::new(0);
53-
static ref LOST_COUNTS: Mutex<Vec<Counter>> = Mutex::new(Vec::new());
54-
}
49+
static SESSION_KEY: LazyLock<Mutex<Option<Vec<u8>>>> = LazyLock::new(|| { Mutex::new(None) });
50+
static COUNTER: LazyLock<Mutex<Counter>> = LazyLock::new(|| { Mutex::new(0) });
51+
static LOST_COUNTS: LazyLock<Mutex<Vec<Counter>>> = LazyLock::new(|| { Mutex::new(Vec::new()) });
5552

5653
fn get_session_key_opt() -> Option<Vec<u8>> {
5754
SESSION_KEY.lock().expect("Session Key is poisoned").clone()
@@ -356,9 +353,7 @@ fn decrypt_base_64(key: &[u8], product: &str) -> errors::Result<Vec<u8>> {
356353
mod rest_server_tests {
357354
use super::*;
358355

359-
lazy_static! {
360-
static ref SYNC_GUARD: Mutex<()> = Mutex::new(());
361-
}
356+
static SYNC_GUARD: LazyLock<Mutex<()>> = LazyLock::new(|| { Mutex::new(()) });
362357

363358
fn init_tests() {
364359
let _guard = SYNC_GUARD.lock().unwrap();

tests/execution_cases.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ async fn execute_update_configuration() {
415415
// Update the configuration
416416
UserSelection::GoTo(Menu::ShowConfiguration),
417417
UserSelection::UpdateConfiguration(new_conf),
418+
// Ack sync error message
419+
UserSelection::UserOption(UserOption::ok()),
418420
// Save
419421
UserSelection::GoTo(Menu::Save(false)),
420422
// Ack saved message

0 commit comments

Comments
 (0)