diff --git a/example/dchat/dchatd/src/main.rs b/example/dchat/dchatd/src/main.rs index cc3ff2b35..c00b6917c 100644 --- a/example/dchat/dchatd/src/main.rs +++ b/example/dchat/dchatd/src/main.rs @@ -112,14 +112,14 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { let dnet_sub = p2p_.dnet_subscribe().await; loop { let event = dnet_sub.receive().await; - debug!("Got dnet event: {:?}", event); + debug!("Got dnet event: {event:?}"); dnet_sub_.notify(vec![event.into()].into()).await; } }, |res| async { match res { Ok(()) | Err(Error::DetachedTaskStopped) => { /* Do nothing */ } - Err(e) => panic!("{}", e), + Err(e) => panic!("{e}"), } }, Error::DetachedTaskStopped, @@ -141,7 +141,7 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { |res| async move { match res { Ok(()) | Err(Error::RpcServerStopped) => dchat.stop_connections().await, - Err(e) => error!("Failed stopping JSON-RPC server: {}", e), + Err(e) => error!("Failed stopping JSON-RPC server: {e}"), } }, Error::RpcServerStopped, diff --git a/src/dht/handler.rs b/src/dht/handler.rs index f361c3c02..d14d75f21 100644 --- a/src/dht/handler.rs +++ b/src/dht/handler.rs @@ -104,7 +104,7 @@ pub trait DhtHandler { let ping_res = self.ping(channel.clone()).await; if let Err(e) = ping_res { - warn!(target: "dht::DhtHandler::channel_task()", "Error while pinging (requesting node id) {}: {}", channel.address(), e); + warn!(target: "dht::DhtHandler::channel_task()", "Error while pinging (requesting node id) {}: {e}", channel.address()); channel.stop().await; continue; } @@ -305,7 +305,7 @@ pub trait DhtHandler { } } Err(e) => { - warn!(target: "dht::DhtHandler::lookup_nodes", "Error looking for nodes: {}", e); + warn!(target: "dht::DhtHandler::lookup_nodes", "Error looking for nodes: {e}"); } } } @@ -378,11 +378,11 @@ pub trait DhtHandler { let connector = Connector::new(self.dht().p2p.settings(), session_weak); let dur = Duration::from_secs(self.dht().settings.timeout); let Ok(connect_res) = timeout(dur, connector.connect(&addr)).await else { - warn!(target: "dht::DhtHandler::get_channel()", "Timeout trying to connect to {}", addr); + warn!(target: "dht::DhtHandler::get_channel()", "Timeout trying to connect to {addr}"); return Err(Error::ConnectTimeout); }; if connect_res.is_err() { - warn!(target: "dht::DhtHandler::get_channel()", "Error while connecting to {}: {}", addr, connect_res.unwrap_err()); + warn!(target: "dht::DhtHandler::get_channel()", "Error while connecting to {addr}: {}", connect_res.unwrap_err()); continue; } let (_, channel) = connect_res.unwrap(); diff --git a/src/geode/mod.rs b/src/geode/mod.rs index 95edf7d9d..49ea03e80 100644 --- a/src/geode/mod.rs +++ b/src/geode/mod.rs @@ -136,7 +136,7 @@ impl Geode { /// This works for both file metadata and directory metadata. /// Returns (chunk hashes, [(file path, file size)]). async fn read_metadata(path: &PathBuf) -> Result<(Vec, Vec<(PathBuf, u64)>)> { - debug!(target: "geode::read_dir_metadata()", "Reading chunks from {:?} (dir)", path); + debug!(target: "geode::read_dir_metadata()", "Reading chunks from {path:?} (dir)"); let mut chunk_hashes = vec![]; let mut files = vec![]; @@ -230,7 +230,7 @@ impl Geode { if let Err(e) = fs::remove_file(path).await { warn!( target: "geode::garbage_collect()", - "[Geode] Garbage collect failed to remove corrupted metadata: {}", e, + "[Geode] Garbage collect failed to remove corrupted metadata: {e}" ); } @@ -393,7 +393,7 @@ impl Geode { let chunk = match self.read_chunk(&mut chunked_file.get_fileseq(), &chunk_index).await { Ok(c) => c, Err(e) => { - warn!("Error while verifying chunks: {}", e); + warn!("Error while verifying chunks: {e}"); break } }; @@ -416,7 +416,7 @@ impl Geode { /// the read failed in any way (could also be the file does not exist). pub async fn get(&self, hash: &blake3::Hash, path: &Path) -> Result { let hash_str = hash_to_string(hash); - info!(target: "geode::get()", "[Geode] Getting chunks for {}...", hash_str); + info!(target: "geode::get()", "[Geode] Getting chunks for {hash_str}..."); // Try to read the file or dir metadata. If it's corrupt, return an error signalling // that garbage collection needs to run. diff --git a/src/rpc/client.rs b/src/rpc/client.rs index 171be2dcf..4ba917e1b 100644 --- a/src/rpc/client.rs +++ b/src/rpc/client.rs @@ -82,7 +82,7 @@ impl RpcClient { |res| async move { match res { Ok(()) | Err(Error::RpcClientStopped) => {} - Err(e) => error!(target: "rpc::client", "[RPC] Client error: {}", e), + Err(e) => error!(target: "rpc::client", "[RPC] Client error: {e}"), } }, Error::RpcClientStopped, @@ -334,7 +334,7 @@ impl RpcChadClient { |res| async move { match res { Ok(()) | Err(Error::RpcClientStopped) => {} - Err(e) => error!(target: "rpc::chad_client", "[RPC] Client error: {}", e), + Err(e) => error!(target: "rpc::chad_client", "[RPC] Client error: {e}"), } }, Error::RpcClientStopped, @@ -419,7 +419,7 @@ impl RpcChadClient { // Check if the IDs match if req_id != rep.id { - debug!(target: "rpc::chad_client", "Skipping response for request {} as its not our latest({})", rep.id, req_id); + debug!(target: "rpc::chad_client", "Skipping response for request {} as its not our latest({req_id})", rep.id); continue } @@ -431,7 +431,7 @@ impl RpcChadClient { // Check if the IDs match if req_id != e.id { - debug!(target: "rpc::chad_client", "Skipping response for request {} as its not our latest({})", e.id, req_id); + debug!(target: "rpc::chad_client", "Skipping response for request {} as its not our latest({req_id})", e.id); continue } diff --git a/src/rpc/clock_sync.rs b/src/rpc/clock_sync.rs index bf857ac2c..d19adafea 100644 --- a/src/rpc/clock_sync.rs +++ b/src/rpc/clock_sync.rs @@ -61,14 +61,14 @@ pub async fn check_clock(peers: &[Url]) -> Result<()> { let mut r = 0; while r < RETRIES { if let Err(e) = clock_check(peers).await { - debug!(target: "rpc::clock_sync", "Error during clock check: {:#?}", e); + debug!(target: "rpc::clock_sync", "Error during clock check: {e:#?}"); r += 1; continue }; break } - debug!(target: "rpc::clock_sync", "System clock check finished. Retries: {}", r); + debug!(target: "rpc::clock_sync", "System clock check finished. Retries: {r}"); if r == RETRIES { return Err(Error::InvalidClock) } @@ -102,9 +102,9 @@ async fn clock_check(_peers: &[Url]) -> Result<()> { Some(p) => Some(p.checked_add(requests_elapsed_time)?), }; - debug!(target: "rpc::clock_sync", "peer_time: {:#?}", peer_time); - debug!(target: "rpc::clock_sync", "ntp_time: {:#?}", ntp_time); - debug!(target: "rpc::clock_sync", "system_time: {:#?}", system_time); + debug!(target: "rpc::clock_sync", "peer_time: {peer_time:#?}"); + debug!(target: "rpc::clock_sync", "ntp_time: {ntp_time:#?}"); + debug!(target: "rpc::clock_sync", "system_time: {system_time:#?}"); // We verify that system time is equal to peer (if exists) and ntp times let check = match peer_time { diff --git a/src/rpc/common.rs b/src/rpc/common.rs index f6b0871a2..23431305e 100644 --- a/src/rpc/common.rs +++ b/src/rpc/common.rs @@ -69,7 +69,7 @@ pub(super) async fn http_read_from_stream_request( let _body_offset = match req.parse(buf) { Ok(v) => v.unwrap(), // TODO: This should check httparse::Status::is_partial() Err(e) => { - error!("[RPC] Failed parsing HTTP request: {}", e); + error!("[RPC] Failed parsing HTTP request: {e}"); return Err(io::ErrorKind::InvalidData.into()) } }; @@ -139,7 +139,7 @@ pub(super) async fn http_read_from_stream_response( let _body_offset = match resp.parse(buf) { Ok(v) => v.unwrap(), // TODO: This should check httparse::Status::is_partial() Err(e) => { - error!("[RPC] Failed parsing HTTP response: {}", e); + error!("[RPC] Failed parsing HTTP response: {e}"); return Err(io::ErrorKind::InvalidData.into()) } }; diff --git a/src/rpc/server.rs b/src/rpc/server.rs index 8c932a6a8..ac8a455b8 100644 --- a/src/rpc/server.rs +++ b/src/rpc/server.rs @@ -71,7 +71,7 @@ pub trait RequestHandler: Sync + Send { async fn stop_connections(&self) { info!(target: "rpc::server", "[RPC] Server stopped, closing connections"); for (i, task) in self.connections().await.iter().enumerate() { - debug!(target: "rpc::server", "Stopping connection #{}", i); + debug!(target: "rpc::server", "Stopping connection #{i}"); task.stop().await; } } @@ -115,7 +115,7 @@ async fn handle_request( let notification = subscription.receive().await; // Push notification - debug!(target: "rpc::server", "{} <-- {}", addr_, notification.stringify().unwrap()); + debug!(target: "rpc::server", "{addr_} <-- {}", notification.stringify().unwrap()); let notification = JsonResult::Notification(notification); let mut writer_lock = writer_.lock().await; @@ -153,7 +153,7 @@ async fn handle_request( JsonResult::SubscriberWithReply(subscriber, reply) => { // Write the response - debug!(target: "rpc::server", "{} <-- {}", addr, reply.stringify()?); + debug!(target: "rpc::server", "{addr} <-- {}", reply.stringify()?); let mut writer_lock = writer.lock().await; if settings.use_http() { http_write_to_stream(&mut writer_lock, &reply.into()).await?; @@ -179,7 +179,7 @@ async fn handle_request( let notification = subscription.receive().await; // Push notification - debug!(target: "rpc::server", "{} <-- {}", addr_, notification.stringify().unwrap()); + debug!(target: "rpc::server", "{addr_} <-- {}", notification.stringify().unwrap()); let notification = JsonResult::Notification(notification); let mut writer_lock = writer_.lock().await; @@ -220,7 +220,7 @@ async fn handle_request( } JsonResult::Response(ref v) => { - debug!(target: "rpc::server", "{} <-- {}", addr, v.stringify()?); + debug!(target: "rpc::server", "{addr} <-- {}", v.stringify()?); let mut writer_lock = writer.lock().await; if settings.use_http() { http_write_to_stream(&mut writer_lock, &rep).await?; @@ -231,7 +231,7 @@ async fn handle_request( } JsonResult::Error(ref v) => { - debug!(target: "rpc::server", "{} <-- {}", addr, v.stringify()?); + debug!(target: "rpc::server", "{addr} <-- {}", v.stringify()?); let mut writer_lock = writer.lock().await; if settings.use_http() { http_write_to_stream(&mut writer_lock, &rep).await?; @@ -288,7 +288,7 @@ pub async fn accept<'a, T: 'a>( Err(e) => { error!( target: "rpc::server::accept()", - "[RPC SERVER] Failed parsing string from read buffer: {}", e, + "[RPC SERVER] Failed parsing string from read buffer: {e}" ); return Err(e.into()) } @@ -300,7 +300,7 @@ pub async fn accept<'a, T: 'a>( Err(e) => { error!( target: "rpc::server::accept()", - "[RPC SERVER] Failed parsing JSON string: {}", e, + "[RPC SERVER] Failed parsing JSON string: {e}" ); return Err(e.into()) } @@ -312,13 +312,13 @@ pub async fn accept<'a, T: 'a>( Err(e) => { error!( target: "rpc::server::accept()", - "[RPC SERVER] Failed casting JSON to a JsonRequest: {}", e, + "[RPC SERVER] Failed casting JSON to a JsonRequest: {e}" ); return Err(e.into()) } }; - debug!(target: "rpc::server", "{} --> {}", addr, val.stringify()?); + debug!(target: "rpc::server", "{addr} --> {}", val.stringify()?); // Create a new task to handle request in the background let task = StoppableTask::new(); @@ -367,7 +367,7 @@ async fn run_accept_loop<'a, T: 'a>( match listener.next().await { Ok((stream, url)) => { let rh_ = rh.clone(); - info!(target: "rpc::server", "[RPC] Server accepted conn from {}", url); + info!(target: "rpc::server", "[RPC] Server accepted conn from {url}"); let (reader, writer) = smol::io::split(stream); let reader = Arc::new(Mutex::new(BufReader::new(reader))); @@ -387,7 +387,7 @@ async fn run_accept_loop<'a, T: 'a>( ex_, ), |_| async move { - info!(target: "rpc::server", "[RPC] Closed conn from {}", url); + info!(target: "rpc::server", "[RPC] Closed conn from {url}"); rh_.clone().unmark_connection(task_.clone()).await; }, Error::ChannelStopped, @@ -403,7 +403,7 @@ async fn run_accept_loop<'a, T: 'a>( _ => { error!( target: "rpc::server::run_accept_loop()", - "[RPC] Server failed listening: {}", e, + "[RPC] Server failed listening: {e}" ); error!( target: "rpc::server::run_accept_loop()", @@ -420,7 +420,7 @@ async fn run_accept_loop<'a, T: 'a>( Err(e) => { error!( target: "rpc::server::run_accept_loop()", - "[RPC] Unhandled listener.next() error: {}", e, + "[RPC] Unhandled listener.next() error: {e}" ); error!( target: "rpc::server::run_accept_loop()", @@ -510,7 +510,7 @@ mod tests { Ok(()) | Err(Error::RpcServerStopped) => { rpc_server_.stop_connections().await } - Err(e) => panic!("{}", e), + Err(e) => panic!("{e}"), } }, Error::RpcServerStopped, diff --git a/src/system/publisher.rs b/src/system/publisher.rs index cc13bacc5..da16f1c9e 100644 --- a/src/system/publisher.rs +++ b/src/system/publisher.rs @@ -45,7 +45,7 @@ impl Subscription { match message_result { Ok(message_result) => message_result, Err(err) => { - panic!("Subscription::receive() recv_queue failed! {}", err); + panic!("Subscription::receive() recv_queue failed! {err}"); } } } @@ -110,7 +110,7 @@ impl Publisher { if let Err(e) = sub.send(message_result.clone()).await { warn!( target: "system::publisher", - "[system::publisher] Error returned sending message in notify_with_exclude() call! {}", e, + "[system::publisher] Error returned sending message in notify_with_exclude() call! {e}" ); } } diff --git a/src/util/cli.rs b/src/util/cli.rs index 2f2b47a28..69d9c05c4 100644 --- a/src/util/cli.rs +++ b/src/util/cli.rs @@ -64,7 +64,7 @@ pub fn spawn_config(path: &Path, contents: &[u8]) -> Result<()> { let mut file = fs::File::create(path)?; file.write_all(contents)?; - println!("Config file created in {:?}. Please review it and try again.", path); + println!("Config file created in {path:?}. Please review it and try again."); std::process::exit(2); } @@ -368,11 +368,11 @@ macro_rules! async_daemonize { } pub fn fg_red(message: &str) -> String { - format!("\x1b[31m{}\x1b[0m", message) + format!("\x1b[31m{message}\x1b[0m") } pub fn fg_green(message: &str) -> String { - format!("\x1b[32m{}\x1b[0m", message) + format!("\x1b[32m{message}\x1b[0m") } pub fn fg_reset() -> String { diff --git a/src/util/time.rs b/src/util/time.rs index 90687213e..806d2e163 100644 --- a/src/util/time.rs +++ b/src/util/time.rs @@ -103,7 +103,7 @@ impl From for Timestamp { impl fmt::Display for Timestamp { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let date = timestamp_to_date(self.0, DateFormat::DateTime); - write!(f, "{}", date) + write!(f, "{date}") } } @@ -138,7 +138,7 @@ impl NanoTimestamp { impl fmt::Display for NanoTimestamp { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let date = timestamp_to_date(self.0.try_into().unwrap(), DateFormat::Nanos); - write!(f, "{}", date) + write!(f, "{date}") } } @@ -350,20 +350,20 @@ pub fn fmt_duration(duration: Duration) -> String { // Include non-zero components for dys, hours and minutes if days > 0 { - parts.push(format!("{}d", days)); + parts.push(format!("{days}d")); } if hours > 0 { - parts.push(format!("{}h", hours)); + parts.push(format!("{hours}h")); } if minutes > 0 { - parts.push(format!("{}m", minutes)); + parts.push(format!("{minutes}m")); } // Include seconds if they are non-zero or if all other components are zero (i.e., 0s) if seconds > 0.0 || (days == 0 && hours == 0 && minutes == 0) { // For durations shorter than 1 minute, include fractional seconds up to 9 decimal places if days == 0 && hours == 0 && minutes == 0 && seconds.fract() != 0.0 { - parts.push(format!("{:.9}s", seconds)); + parts.push(format!("{seconds:.9}s")); } else { // Otherwise, include rounded whole seconds parts.push(format!("{}s", seconds.round() as u64)); @@ -454,7 +454,7 @@ mod tests { for timestamp_str in invalid_timestamps { let result = DateTime::from_timestamp_str(timestamp_str); - assert!(result.is_err(), "Expected error for invalid timestamp '{}'", timestamp_str); + assert!(result.is_err(), "Expected error for invalid timestamp '{timestamp_str}'"); } } #[test] diff --git a/tests/dyn_circuit.rs b/tests/dyn_circuit.rs index 4cafeddba..7fde0f469 100644 --- a/tests/dyn_circuit.rs +++ b/tests/dyn_circuit.rs @@ -115,7 +115,7 @@ fn dyn_circuit() { let prover = MockProver::run(K, &circuit, vec![public_inputs]).unwrap(); prover.assert_satisfied(); - let title = format!("target/dynamic_circuit_{:0>2}.png", i); + let title = format!("target/dynamic_circuit_{i:0>2}.png"); let root = BitMapBackend::new(&title, (800, 600)).into_drawing_area(); CircuitLayout::default().render(K, &circuit, &root).unwrap(); } diff --git a/tests/jsonrpc.rs b/tests/jsonrpc.rs index b370ba986..0d8eb5b5f 100644 --- a/tests/jsonrpc.rs +++ b/tests/jsonrpc.rs @@ -119,7 +119,7 @@ fn jsonrpc_reqrep() -> Result<()> { |res| async move { match res { Ok(()) | Err(Error::RpcServerStopped) => rpcsrv_.stop_connections().await, - Err(e) => eprintln!("Failed starting JSON-RPC server: {}", e), + Err(e) => eprintln!("Failed starting JSON-RPC server: {e}"), } }, Error::RpcServerStopped, @@ -172,7 +172,7 @@ fn http_jsonrpc_reqrep() -> Result<()> { |res| async move { match res { Ok(()) | Err(Error::RpcServerStopped) => rpcsrv_.stop_connections().await, - Err(e) => eprintln!("Failed starting JSON-RPC server: {}", e), + Err(e) => eprintln!("Failed starting JSON-RPC server: {e}"), } }, Error::RpcServerStopped, diff --git a/tests/vdf_eval.rs b/tests/vdf_eval.rs index e4455f14f..6fcb1ef10 100644 --- a/tests/vdf_eval.rs +++ b/tests/vdf_eval.rs @@ -41,16 +41,16 @@ fn evaluate_vdf() { for n_steps in steps { let now = Instant::now(); - print!("E with N={} ... ", n_steps); + print!("E with N={n_steps} ... "); let witness = mimc_vdf::eval(&challenge, n_steps); let eval_elapsed = now.elapsed(); - println!("{:?}", eval_elapsed); + println!("{eval_elapsed:?}"); let now = Instant::now(); - print!("V with N={} ... ", n_steps); + print!("V with N={n_steps} ... "); assert!(mimc_vdf::verify(&challenge, n_steps, &witness)); let verify_elapsed = now.elapsed(); - println!("{:?}", verify_elapsed); + println!("{verify_elapsed:?}"); map.insert(n_steps, (eval_elapsed, verify_elapsed)); } @@ -60,8 +60,8 @@ fn evaluate_vdf() { table.set_titles(row!["n_steps", "eval time", "verify time"]); for n_steps in steps { let (eval, verify) = map.get(&n_steps).unwrap(); - table.add_row(row![format!("{}", n_steps), format!("{:?}", eval), format!("{:?}", verify)]); + table.add_row(row![format!("{n_steps}"), format!("{eval:?}"), format!("{verify:?}")]); } - println!("\n\n{}", table); + println!("\n\n{table}"); }