From 6333fb0bd36635d331a7e9ccab0fa6f15f40c14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 1 Jun 2022 02:02:30 +1200 Subject: [PATCH] Use newer format! syntax --- src/drivers.rs | 6 +++--- src/helpers.rs | 48 +++++++++++++----------------------------------- src/main.rs | 8 ++++---- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/src/drivers.rs b/src/drivers.rs index 1ca2ed3f..49b615c1 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -98,9 +98,9 @@ pub async fn fetch_crate_cratesio( // Download crate to temporary dir (crates.io or git?) let crate_url = format!("https://crates.io/{}", version.dl_path); - let tgz_path = temp_dir.join(format!("{}.tgz", name)); + let tgz_path = temp_dir.join(format!("{name}.tgz")); - debug!("Fetching crate from: {}", crate_url); + debug!("Fetching crate from: {crate_url}"); // Download crate download(&crate_url, &tgz_path).await?; @@ -108,7 +108,7 @@ pub async fn fetch_crate_cratesio( // Decompress downloaded tgz debug!("Decompressing crate archive"); extract(&tgz_path, PkgFmt::Tgz, &temp_dir)?; - let crate_path = temp_dir.join(format!("{}-{}", name, version_name)); + let crate_path = temp_dir.join(format!("{name}-{version_name}")); // Return crate directory Ok(crate_path) diff --git a/src/helpers.rs b/src/helpers.rs index 9471eb4f..27b22551 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -4,10 +4,9 @@ use std::{ path::{Path, PathBuf}, }; -use log::{debug, info}; - use cargo_toml::Manifest; use flate2::read::GzDecoder; +use log::{debug, info}; use reqwest::Method; use serde::Serialize; use tar::Archive; @@ -44,7 +43,7 @@ pub async fn remote_exists(url: Url, method: Method) -> Result>(url: &str, path: P) -> Result<(), BinstallError> { let url = Url::parse(url)?; - debug!("Downloading from: '{}'", url); + debug!("Downloading from: '{url}'"); let resp = reqwest::get(url.clone()) .await @@ -72,14 +71,13 @@ pub fn extract, P: AsRef>( fmt: PkgFmt, path: P, ) -> Result<(), BinstallError> { + let source = source.as_ref(); + let path = path.as_ref(); + match fmt { PkgFmt::Tar => { // Extract to install dir - debug!( - "Extracting from tar archive '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Extracting from tar archive '{source:?}' to `{path:?}`"); let dat = fs::File::open(source)?; let mut tar = Archive::new(dat); @@ -88,11 +86,7 @@ pub fn extract, P: AsRef>( } PkgFmt::Tgz => { // Extract to install dir - debug!( - "Decompressing from tgz archive '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Decompressing from tgz archive '{source:?}' to `{path:?}`"); let dat = fs::File::open(source)?; let tar = GzDecoder::new(dat); @@ -102,11 +96,7 @@ pub fn extract, P: AsRef>( } PkgFmt::Txz => { // Extract to install dir - debug!( - "Decompressing from txz archive '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Decompressing from txz archive '{source:?}' to `{path:?}`"); let dat = fs::File::open(source)?; let tar = XzDecoder::new(dat); @@ -116,11 +106,7 @@ pub fn extract, P: AsRef>( } PkgFmt::Tzstd => { // Extract to install dir - debug!( - "Decompressing from tzstd archive '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Decompressing from tzstd archive '{source:?}' to `{path:?}`"); let dat = std::fs::File::open(source)?; @@ -135,11 +121,7 @@ pub fn extract, P: AsRef>( } PkgFmt::Zip => { // Extract to install dir - debug!( - "Decompressing from zip archive '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Decompressing from zip archive '{source:?}' to `{path:?}`"); let dat = fs::File::open(source)?; let mut zip = ZipArchive::new(dat)?; @@ -147,11 +129,7 @@ pub fn extract, P: AsRef>( zip.extract(path)?; } PkgFmt::Bin => { - debug!( - "Copying binary '{:?}' to `{:?}`", - source.as_ref(), - path.as_ref() - ); + debug!("Copying binary '{source:?}' to `{path:?}`"); // Copy to install dir fs::copy(source, path)?; } @@ -170,12 +148,12 @@ pub fn get_install_path>(install_path: Option

) -> Option, target: &str info!("Cargo finished successfully"); Ok(()) } else { - error!("Cargo errored! {:?}", status); + error!("Cargo errored! {status:?}"); Err(miette!("Cargo install error")) } }