Skip to content

Commit

Permalink
migrate from lazy_static to once_cell across project
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed May 30, 2023
1 parent ae96e05 commit bbfc2fd
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 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 client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dialoguer = { version = "0.10", default-features = false }
hostsfile = { path = "../hostsfile" }
indoc = "1"
ipnet = { version = "2.4", features = ["serde"] }
lazy_static = "1"
log = "0.4"
regex = { version = "1", default-features = false, features = ["std"] }
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -32,6 +31,7 @@ ureq = { version = "2", default-features = false, features = ["json"] }
wireguard-control = { path = "../wireguard-control" }

[dev-dependencies]
lazy_static = "1"
tempfile = "3"

[package.metadata.deb]
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ dialoguer = { version = "0.10", default-features = false }
hyper = { version = "0.14", default-features = false, features = ["http1", "server", "runtime", "stream"] }
indoc = "1"
ipnet = { version = "2.4", features = ["serde"] }
lazy_static = "1"
libc = "0.2"
libsqlite3-sys = "0.25"
log = "0.4"
once_cell = "1"
parking_lot = "0.12"
pretty_env_logger = "0.4"
publicip = { path = "../publicip" }
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod user;
/// Inject the collected endpoints from the WG interface into a list of peers.
/// This is essentially what adds NAT holepunching functionality.
pub fn inject_endpoints(session: &Session, peers: &mut Vec<Peer>) {
for mut peer in peers {
for peer in peers {
if peer.contents.endpoint.is_none() {
if let Some(endpoint) = session.context.endpoints.read().get(&peer.public_key) {
peer.contents.endpoint = Some(endpoint.to_owned().into());
Expand Down
10 changes: 4 additions & 6 deletions server/src/db/peer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::DatabaseCidr;
use crate::ServerError;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use rusqlite::{params, types::Type, Connection};
use shared::{IpNetExt, Peer, PeerContents, PERSISTENT_KEEPALIVE_INTERVAL_SECS};
Expand Down Expand Up @@ -42,11 +42,9 @@ pub static COLUMNS: &[&str] = &[
"candidates",
];

lazy_static! {
/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames.
/// Note that the full length also must be maximum 63 characters, which this regex does not check.
static ref PEER_NAME_REGEX: Regex = Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap();
}
/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames.
/// Note that the full length also must be maximum 63 characters, which this regex does not check.
static PEER_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap());

#[derive(Debug)]
pub struct DatabasePeer {
Expand Down
2 changes: 1 addition & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ colored = "2.0"
dialoguer = { version = "0.10", default-features = false }
indoc = "1"
ipnet = { version = "2.4", features = ["serde"] }
lazy_static = "1"
libc = "0.2"
log = "0.4"
once_cell = "1"
publicip = { path = "../publicip" }
regex = "1"
serde = { version = "1", features = ["derive"] }
Expand Down
6 changes: 2 additions & 4 deletions shared/src/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::anyhow;
use colored::*;
use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select};
use ipnet::IpNet;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use publicip::Preference;
use std::{
fmt::{Debug, Display},
Expand All @@ -20,9 +20,7 @@ use std::{
};
use wireguard_control::{InterfaceName, KeyPair};

lazy_static! {
pub static ref THEME: ColorfulTheme = ColorfulTheme::default();
}
pub static THEME: Lazy<ColorfulTheme> = Lazy::new(ColorfulTheme::default);

pub fn ensure_interactive(prompt: &str) -> Result<(), io::Error> {
if atty::is(atty::Stream::Stdin) {
Expand Down
10 changes: 4 additions & 6 deletions shared/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Error};
use clap::Args;
use ipnet::IpNet;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -758,11 +758,9 @@ impl From<Timestring> for Duration {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Hostname(String);

lazy_static! {
/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames.
/// Note that the full length also must be maximum 63 characters, which this regex does not check.
static ref HOSTNAME_REGEX: Regex = Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap();
}
/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames.
/// Note that the full length also must be maximum 63 characters, which this regex does not check.
static HOSTNAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap());

impl Hostname {
pub fn is_valid(name: &str) -> bool {
Expand Down

0 comments on commit bbfc2fd

Please sign in to comment.