diff --git a/Cargo.toml b/Cargo.toml index 13abad5..0754065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,10 +28,6 @@ linux-secret-service-rt-tokio-crypto-openssl = ["secret-service/rt-tokio-crypto- linux-no-secret-service = ["linux-default-keyutils"] linux-default-keyutils = ["linux-keyutils"] - -[dependencies] -lazy_static = "1" - [target.'cfg(target_os = "macos")'.dependencies] security-framework = { version = "2.6", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 4646d83..d2c401f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,16 +216,14 @@ pub fn set_default_credential_builder(new: Box) { } fn build_default_credential(target: Option<&str>, service: &str, user: &str) -> Result { - lazy_static::lazy_static! { - static ref DEFAULT: Box = default::default_credential_builder(); - } + static DEFAULT: std::sync::OnceLock> = std::sync::OnceLock::new(); let guard = DEFAULT_BUILDER .read() .expect("Poisoned RwLock in keyring-rs: please report a bug!"); - let builder = match guard.inner.as_ref() { - Some(builder) => builder, - None => &DEFAULT, - }; + let builder = guard + .inner + .as_ref() + .unwrap_or_else(|| DEFAULT.get_or_init(|| default::default_credential_builder())); let credential = builder.build(target, service, user)?; Ok(Entry { inner: credential }) }