Skip to content

Commit

Permalink
Replace lazy_static with std::cell:OnceLock
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Apr 17, 2024
1 parent 08b7b70 commit d34b756
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ futures-core = "0.3"
futures-util = "0.3"
futures-sink = "0.3"
keyed_priority_queue = "0.4"
lazy_static = "1"
lru = "0.12.0"
mio = { version = "0.8.0", features = ["os-poll", "net"] }
mysql_common = { version = "0.32", default-features = false }
Expand Down
26 changes: 8 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,8 @@ pub mod prelude {

#[doc(hidden)]
pub mod test_misc {
use lazy_static::lazy_static;

use std::env;
use std::sync::OnceLock;

use crate::opts::{Opts, OptsBuilder, SslOpts};

Expand All @@ -621,26 +620,17 @@ pub mod test_misc {
_dummy(err);
}

lazy_static! {
pub static ref DATABASE_URL: String = {
pub fn get_opts() -> OptsBuilder {
static DATABASE_OPTS: OnceLock<Opts> = OnceLock::new();
let database_opts = DATABASE_OPTS.get_or_init(|| {
if let Ok(url) = env::var("DATABASE_URL") {
let opts = Opts::from_url(&url).expect("DATABASE_URL invalid");
if opts
.db_name()
.expect("a database name is required")
.is_empty()
{
panic!("database name is empty");
}
url
Opts::from_url(&url).expect("DATABASE_URL invalid")
} else {
"mysql://root:password@localhost:3307/mysql".into()
Opts::from_url("mysql://root:password@localhost:3307/mysql").unwrap()
}
};
}
});

pub fn get_opts() -> OptsBuilder {
let mut builder = OptsBuilder::from_opts(Opts::from_url(&DATABASE_URL).unwrap());
let mut builder = OptsBuilder::from_opts(database_opts.clone());
if test_ssl() {
let ssl_opts = SslOpts::default()
.with_danger_skip_domain_validation(true)
Expand Down

0 comments on commit d34b756

Please sign in to comment.