Skip to content

Commit

Permalink
Replace lazy_static with OnceLock
Browse files Browse the repository at this point in the history
  • Loading branch information
russellbanks committed Jan 1, 2024
1 parent fbeb36b commit 9937846
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,14 @@ pub fn set_default_credential_builder(new: Box<CredentialBuilder>) {
}

fn build_default_credential(target: Option<&str>, service: &str, user: &str) -> Result<Entry> {
lazy_static::lazy_static! {
static ref DEFAULT: Box<CredentialBuilder> = default::default_credential_builder();
}
static DEFAULT: std::sync::OnceLock<Box<CredentialBuilder>> = 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 })
}
Expand Down

0 comments on commit 9937846

Please sign in to comment.