Skip to content

Commit

Permalink
Merge pull request #419 from jasonmokk/replace-deprecated-lazy-static
Browse files Browse the repository at this point in the history
Replace deprecated `lazy_static` with once_cell
  • Loading branch information
ndelvalle authored May 24, 2024
2 parents 49b78b6 + 98b99db commit 2cf267b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jsonwebtoken = "8.3.0"
once_cell = "1.19.0"
bcrypt = "0.15.1"
validator = { version = "0.18.1", features = ["derive"] }
lazy_static = "1.4.0"
mime = "0.3.17"
bytes = "1.6.0"

Expand Down
8 changes: 4 additions & 4 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use config::{Config, ConfigError, Environment, File};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use serde::Deserialize;
use std::{env, fmt};

lazy_static! {
pub static ref SETTINGS: Settings = Settings::new().expect("Failed to setup settings");
}
pub static SETTINGS: Lazy<Settings> = Lazy::new(|| {
Settings::new().expect("Failed to setup settings")
});

#[derive(Debug, Clone, Deserialize)]
pub struct Server {
Expand Down
7 changes: 2 additions & 5 deletions src/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bson::doc;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::net::SocketAddr;
use tokio::runtime::Runtime;
use tokio::sync::OnceCell;
Expand All @@ -11,6 +11,7 @@ use crate::settings::SETTINGS;
use crate::utils::models::ModelExt;

static API: OnceCell<()> = OnceCell::const_new();
static RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().unwrap());

pub async fn start_api_once() {
API
Expand All @@ -31,10 +32,6 @@ pub async fn start_api_once() {
.await;
}

lazy_static! {
static ref RUNTIME: Runtime = Runtime::new().unwrap();
}

pub fn use_app<F>(test: F)
where
F: std::future::Future,
Expand Down

0 comments on commit 2cf267b

Please sign in to comment.