Skip to content

Commit

Permalink
Switch from lazy_static to once_cell (#442)
Browse files Browse the repository at this point in the history
The latter will hopefully eventually be upstreamed into `std`.
  • Loading branch information
tony-iqlusion authored Nov 14, 2022
1 parent 57bb088 commit 5c42590
Show file tree
Hide file tree
Showing 5 changed files with 15 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ zeroize = "1"

[dev-dependencies]
env_logger = "0.9"
lazy_static = "1"
once_cell = "1"
rsa = { version = "0.7.1", features = ["hazmat"] }
signature = { version = "1.6.4", features = ["hazmat-preview"] }

Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ rust-version = "1.56"
[dependencies]
clap = { version = "4", features = ["derive"] }
env_logger = "0.9"
lazy_static = "1"
log = "0.4"
once_cell = "1"
sha2 = "0.10"
subtle-encoding = "0.5"
termcolor = "1"
Expand Down
16 changes: 7 additions & 9 deletions cli/src/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Status messages
use lazy_static::lazy_static;
use log::debug;
use once_cell::sync::Lazy;
use sha2::{Digest, Sha256};
use std::{
io::{self, Write},
Expand Down Expand Up @@ -59,16 +59,14 @@ macro_rules! status_err {
};
}

lazy_static! {
/// Color configuration
static ref COLOR_CHOICE: Mutex<Option<ColorChoice>> = Mutex::new(None);
/// Color configuration
static COLOR_CHOICE: Lazy<Mutex<Option<ColorChoice>>> = Lazy::new(|| Mutex::new(None));

/// Standard output
pub static ref STDOUT: StandardStream = StandardStream::stdout(get_color_choice());
/// Standard output
pub static STDOUT: Lazy<StandardStream> = Lazy::new(|| StandardStream::stdout(get_color_choice()));

/// Standard error
pub static ref STDERR: StandardStream = StandardStream::stderr(get_color_choice());
}
/// Standard error
pub static STDERR: Lazy<StandardStream> = Lazy::new(|| StandardStream::stderr(get_color_choice()));

/// Obtain the color configuration.
///
Expand Down
13 changes: 4 additions & 9 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)]

use lazy_static::lazy_static;
use log::trace;
use once_cell::sync::Lazy;
use rand_core::{OsRng, RngCore};
use rsa::pkcs1v15;
use sha2::{Digest, Sha256};
Expand All @@ -18,13 +18,7 @@ use yubikey::{
Error, MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey,
};

lazy_static! {
/// Provide thread-safe access to a YubiKey
static ref YUBIKEY: Mutex<YubiKey> = init_yubikey();
}

/// One-time test initialization and setup
fn init_yubikey() -> Mutex<YubiKey> {
static YUBIKEY: Lazy<Mutex<YubiKey>> = Lazy::new(|| {
// Only show logs if `RUST_LOG` is set
if env::var("RUST_LOG").is_ok() {
env_logger::builder().format_timestamp(None).init();
Expand All @@ -36,11 +30,12 @@ fn init_yubikey() -> Mutex<YubiKey> {
} else {
YubiKey::open().unwrap()
};

trace!("serial: {}", yubikey.serial());
trace!("version: {}", yubikey.version());

Mutex::new(yubikey)
}
});

//
// CCCID support
Expand Down

0 comments on commit 5c42590

Please sign in to comment.