diff --git a/logger/src/lib.rs b/logger/src/lib.rs index 2b0e469f2..fdc5d04d5 100644 --- a/logger/src/lib.rs +++ b/logger/src/lib.rs @@ -2,9 +2,9 @@ //! `setup()` may be called multiple times. use env_logger; -use std::sync::{Once, ONCE_INIT}; +use std::sync::Once; -static INIT: Once = ONCE_INIT; +static INIT: Once = Once::new(); /// Setup function that is only run once, even if called multiple times. pub fn setup() { diff --git a/metrics/src/counter.rs b/metrics/src/counter.rs index 71463790b..1f06db1ca 100644 --- a/metrics/src/counter.rs +++ b/metrics/src/counter.rs @@ -62,7 +62,7 @@ macro_rules! inc_new_counter { if log_enabled!($level) { static mut INC_NEW_COUNTER: $crate::counter::Counter = create_counter!($name, $lograte, $metricsrate); - static INIT_HOOK: std::sync::Once = std::sync::ONCE_INIT; + static INIT_HOOK: std::sync::Once = std::sync::Once::new(); unsafe { INIT_HOOK.call_once(|| { INC_NEW_COUNTER.init(); @@ -197,11 +197,11 @@ mod tests { use serial_test_derive::serial; use std::env; use std::sync::atomic::Ordering; - use std::sync::{Once, RwLock, ONCE_INIT}; + use std::sync::{Once, RwLock}; fn get_env_lock() -> &'static RwLock<()> { static mut ENV_LOCK: Option> = None; - static INIT_HOOK: Once = ONCE_INIT; + static INIT_HOOK: Once = Once::new(); unsafe { INIT_HOOK.call_once(|| { diff --git a/metrics/src/metrics.rs b/metrics/src/metrics.rs index 32b7a7725..73b5f10f6 100644 --- a/metrics/src/metrics.rs +++ b/metrics/src/metrics.rs @@ -8,7 +8,7 @@ use solana_sdk::hash::hash; use solana_sdk::timing; use std::collections::HashMap; use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender}; -use std::sync::{Arc, Barrier, Mutex, Once, ONCE_INIT}; +use std::sync::{Arc, Barrier, Mutex, Once}; use std::thread; use std::time::{Duration, Instant}; use std::{cmp, env}; @@ -379,7 +379,7 @@ impl Drop for MetricsAgent { } fn get_singleton_agent() -> Arc> { - static INIT: Once = ONCE_INIT; + static INIT: Once = Once::new(); static mut AGENT: Option>> = None; unsafe { INIT.call_once(|| AGENT = Some(Arc::new(Mutex::new(MetricsAgent::default())))); @@ -430,7 +430,7 @@ pub fn flush() { /// Hook the panic handler to generate a data point on each panic pub fn set_panic_hook(program: &'static str) { use std::panic; - static SET_HOOK: Once = ONCE_INIT; + static SET_HOOK: Once = Once::new(); SET_HOOK.call_once(|| { let default_hook = panic::take_hook(); panic::set_hook(Box::new(move |ono| { diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index f853f1ba4..59b9734a3 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -69,7 +69,7 @@ impl fmt::Display for Pubkey { } } -pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box> { +pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box> { let printable = format!("{}", pubkey); let serialized = serde_json::to_string(&printable)?; @@ -82,7 +82,7 @@ pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box Result> { +pub fn read_pubkey(infile: &str) -> Result> { let f = File::open(infile.to_string())?; let printable: String = serde_json::from_reader(f)?; Ok(Pubkey::from_str(&printable)?) @@ -166,7 +166,7 @@ mod tests { } #[test] - fn test_read_write_pubkey() -> Result<(), Box> { + fn test_read_write_pubkey() -> Result<(), Box> { let filename = "test_pubkey.json"; let pubkey = Pubkey::new_rand(); write_pubkey(filename, pubkey)?; diff --git a/sdk/src/signature.rs b/sdk/src/signature.rs index a79f278eb..1742e0473 100644 --- a/sdk/src/signature.rs +++ b/sdk/src/signature.rs @@ -118,7 +118,7 @@ impl KeypairUtil for Keypair { } } -pub fn read_keypair(path: &str) -> Result> { +pub fn read_keypair(path: &str) -> Result> { let file = File::open(path.to_string())?; let bytes: Vec = serde_json::from_reader(file)?; let keypair = Keypair::from_bytes(&bytes) @@ -126,7 +126,7 @@ pub fn read_keypair(path: &str) -> Result> { Ok(keypair) } -pub fn gen_keypair_file(outfile: &str) -> Result> { +pub fn gen_keypair_file(outfile: &str) -> Result> { let keypair_bytes = Keypair::new().to_bytes(); let serialized = serde_json::to_string(&keypair_bytes.to_vec())?;