Skip to content

Commit

Permalink
Replace some use of lazy_static with once_cell
Browse files Browse the repository at this point in the history
To align more with the upcoming standardizations within the Rust
ecosystem which started with the release of `1.70.0` and the inevitable
deprecation of `lazy_static`:
rust-lang-nursery/lazy-static.rs#214
  • Loading branch information
MarkusPettersson98 committed Jun 22, 2023
1 parent 3400972 commit 7e0e1bf
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 173 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mullvad-management-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ log = "0.4"

[target.'cfg(unix)'.dependencies]
nix = "0.23"
lazy_static = "1.0"
once_cell = "1.13"

[build-dependencies]
tonic-build = { version = "0.8", default-features = false, features = ["transport", "prost"] }
8 changes: 4 additions & 4 deletions mullvad-management-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub type ManagementServiceClient =
pub use types::management_service_server::{ManagementService, ManagementServiceServer};

#[cfg(unix)]
lazy_static::lazy_static! {
static ref MULLVAD_MANAGEMENT_SOCKET_GROUP: Option<String> = env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP")
.ok();
}
use once_cell::sync::Lazy;
#[cfg(unix)]
static MULLVAD_MANAGEMENT_SOCKET_GROUP: Lazy<Option<String>> =
Lazy::new(|| env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP").ok());

#[derive(err_derive::Error, Debug)]
#[error(no_from)]
Expand Down
2 changes: 1 addition & 1 deletion mullvad-problem-report/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
[dependencies]
dirs-next = "2.0"
err-derive = "0.3.1"
lazy_static = "1.0"
once_cell = "1.13"
log = "0.4"
regex = "1.0"
uuid = { version = "0.8", features = ["v4"] }
Expand Down
40 changes: 17 additions & 23 deletions mullvad-problem-report/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(rust_2018_idioms)]

use lazy_static::lazy_static;
use mullvad_api::proxy::ApiConnectionMode;
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
borrow::Cow,
Expand Down Expand Up @@ -413,9 +413,7 @@ impl ProblemReport {
}

fn redact_account_number(input: &str) -> Cow<'_, str> {
lazy_static! {
static ref RE: Regex = Regex::new("\\d{16}").unwrap();
}
static RE: Lazy<Regex> = Lazy::new(|| Regex::new("\\d{16}").unwrap());
RE.replace_all(input, "[REDACTED ACCOUNT NUMBER]")
}

Expand All @@ -424,29 +422,25 @@ impl ProblemReport {
}

fn redact_network_info(input: &str) -> Cow<'_, str> {
lazy_static! {
static ref RE: Regex = {
let boundary = "[^0-9a-zA-Z.:]";
let combined_pattern = format!(
"(?P<start>^|{})(?:{}|{}|{})",
boundary,
build_ipv4_regex(),
build_ipv6_regex(),
build_mac_regex(),
);
Regex::new(&combined_pattern).unwrap()
};
}
static RE: Lazy<Regex> = Lazy::new(|| {
let boundary = "[^0-9a-zA-Z.:]";
let combined_pattern = format!(
"(?P<start>^|{})(?:{}|{}|{})",
boundary,
build_ipv4_regex(),
build_ipv6_regex(),
build_mac_regex(),
);
Regex::new(&combined_pattern).unwrap()
});
RE.replace_all(input, "$start[REDACTED]")
}

fn redact_guids(input: &str) -> Cow<'_, str> {
lazy_static! {
static ref RE: Regex = Regex::new(
r#"(?i)\{?[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}?"#
)
.unwrap();
}
static RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"(?i)\{?[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}?"#)
.unwrap()
});
RE.replace_all(input, "[REDACTED]")
}

Expand Down
2 changes: 1 addition & 1 deletion mullvad-relay-selector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ mullvad-api = { path = "../mullvad-api" }
mullvad-types = { path = "../mullvad-types" }

[dev-dependencies]
lazy_static = "1.0"
once_cell = "1.13"
Loading

0 comments on commit 7e0e1bf

Please sign in to comment.