diff --git a/src/alias.rs b/src/alias.rs index 3c444c6..b23366e 100644 --- a/src/alias.rs +++ b/src/alias.rs @@ -17,13 +17,13 @@ pub fn create_alias( let alias_dir = aliases_dir.join(common_name); remove_symlink_dir(&alias_dir).ok(); - symlink_dir(&version_dir, &alias_dir)?; + symlink_dir(version_dir, &alias_dir)?; Ok(()) } pub fn list_aliases(config: &FnmConfig) -> std::io::Result> { - let vec: Vec<_> = std::fs::read_dir(&config.aliases_dir())? + let vec: Vec<_> = std::fs::read_dir(config.aliases_dir())? .filter_map(Result::ok) .filter_map(|x| TryInto::::try_into(x.path().as_path()).ok()) .collect(); diff --git a/src/arch.rs b/src/arch.rs index 64f5f67..82bda1b 100644 --- a/src/arch.rs +++ b/src/arch.rs @@ -48,7 +48,7 @@ impl std::str::FromStr for Arch { "ppc64le" => Ok(Arch::Ppc64le), "ppc64" => Ok(Arch::Ppc64), "s390x" => Ok(Arch::S390x), - unknown => Err(ArchError::new(&format!("Unknown Arch: {}", unknown))), + unknown => Err(ArchError::new(&format!("Unknown Arch: {unknown}"))), } } } @@ -65,7 +65,7 @@ impl std::fmt::Display for Arch { Arch::S390x => String::from("s390x"), }; - write!(f, "{}", arch_str) + write!(f, "{arch_str}") } } diff --git a/src/commands/command.rs b/src/commands/command.rs index 6ec6c03..d70ff79 100644 --- a/src/commands/command.rs +++ b/src/commands/command.rs @@ -7,7 +7,7 @@ pub trait Command: Sized { fn apply(self, config: &FnmConfig) -> Result<(), Self::Error>; fn handle_error(err: Self::Error, config: &FnmConfig) { - let err_s = format!("{}", err); + let err_s = format!("{err}"); outln!(config, Error, "{} {}", "error:".red().bold(), err_s.red()); std::process::exit(1); } diff --git a/src/commands/completions.rs b/src/commands/completions.rs index 35fc156..605944e 100644 --- a/src/commands/completions.rs +++ b/src/commands/completions.rs @@ -43,7 +43,7 @@ pub enum Error { fn shells_as_string() -> String { AVAILABLE_SHELLS .iter() - .map(|x| format!("* {}", x)) + .map(|x| format!("* {x}")) .collect::>() .join("\n") } diff --git a/src/commands/current.rs b/src/commands/current.rs index 1081f72..94e1ba0 100644 --- a/src/commands/current.rs +++ b/src/commands/current.rs @@ -13,7 +13,7 @@ impl Command for Current { Some(ver) => ver.v_str(), None => "none".into(), }; - println!("{}", version_string); + println!("{version_string}"); Ok(()) } } diff --git a/src/commands/env.rs b/src/commands/env.rs index 6bb4427..fc82a9e 100644 --- a/src/commands/env.rs +++ b/src/commands/env.rs @@ -114,7 +114,7 @@ impl Command for Env { println!("{}", shell.use_on_cd(config)?); } if let Some(v) = shell.rehash() { - println!("{}", v); + println!("{v}"); } Ok(()) @@ -147,7 +147,7 @@ pub enum Error { fn shells_as_string() -> String { AVAILABLE_SHELLS .iter() - .map(|x| format!("* {}", x)) + .map(|x| format!("* {x}")) .collect::>() .join("\n") } diff --git a/src/commands/ls_local.rs b/src/commands/ls_local.rs index 438a6cc..b87c4a2 100644 --- a/src/commands/ls_local.rs +++ b/src/commands/ls_local.rs @@ -35,12 +35,12 @@ impl super::command::Command for LsLocal { } }; - let version_str = format!("* {}{}", version, version_aliases); + let version_str = format!("* {version}{version_aliases}"); if curr_version == Some(version) { println!("{}", version_str.cyan()); } else { - println!("{}", version_str); + println!("{version_str}"); } } Ok(()) diff --git a/src/commands/ls_remote.rs b/src/commands/ls_remote.rs index 15cccc1..015b3ac 100644 --- a/src/commands/ls_remote.rs +++ b/src/commands/ls_remote.rs @@ -14,7 +14,7 @@ impl super::command::Command for LsRemote { for version in all_versions { print!("{}", version.version); if let Some(lts) = &version.lts { - print!(" ({})", lts); + print!(" ({lts})"); } println!(); } diff --git a/src/commands/uninstall.rs b/src/commands/uninstall.rs index b254260..91d1a88 100644 --- a/src/commands/uninstall.rs +++ b/src/commands/uninstall.rs @@ -92,7 +92,7 @@ pub enum Error { CantInferVersion, #[error("Can't uninstall system version")] CantUninstallSystemVersion, - #[error("Too many versions had matched, please be more specific.\nFound {} matching versions, expected 1:\n{}", matched_versions.len(), matched_versions.iter().map(|v| format!("* {}", v)).collect::>().join("\n"))] + #[error("Too many versions had matched, please be more specific.\nFound {} matching versions, expected 1:\n{}", matched_versions.len(), matched_versions.iter().map(|v| format!("* {v}")).collect::>().join("\n"))] PleaseBeMoreSpecificToDelete { matched_versions: Vec }, #[error("Can't find a matching version")] CantFindVersion, diff --git a/src/directory_portal.rs b/src/directory_portal.rs index 04eb6e8..f615fe7 100644 --- a/src/directory_portal.rs +++ b/src/directory_portal.rs @@ -57,7 +57,7 @@ mod tests { let tempdir = tempdir().expect("Can't generate a temp directory"); let portal = DirectoryPortal::new_in(std::env::temp_dir(), tempdir.path().join("subdir")); let new_file_path = portal.to_path_buf().join("README.md"); - std::fs::write(&new_file_path, "Hello world!").expect("Can't write file"); + std::fs::write(new_file_path, "Hello world!").expect("Can't write file"); let target = portal.teleport().expect("Can't close directory portal"); let file_exists: Vec<_> = target diff --git a/src/downloader.rs b/src/downloader.rs index 866481f..3e47039 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -171,8 +171,7 @@ mod tests { let version = Version::parse("12.0.0").unwrap(); let arch = Arch::X64; let node_dist_mirror = Url::parse("https://nodejs.org/dist/").unwrap(); - install_node_dist(&version, &node_dist_mirror, &path, &arch) - .expect("Can't install Node 12"); + install_node_dist(&version, &node_dist_mirror, path, &arch).expect("Can't install Node 12"); let mut location_path = path.join(version.v_str()).join("installation"); diff --git a/src/lts.rs b/src/lts.rs index a256bb0..2dac08d 100644 --- a/src/lts.rs +++ b/src/lts.rs @@ -23,7 +23,7 @@ impl Display for LtsType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Latest => write!(f, "latest"), - Self::CodeName(s) => write!(f, "{}", s), + Self::CodeName(s) => write!(f, "{s}"), } } } diff --git a/src/remote_node_index.rs b/src/remote_node_index.rs index 6ff6fe8..4c9f3bd 100644 --- a/src/remote_node_index.rs +++ b/src/remote_node_index.rs @@ -72,7 +72,7 @@ pub struct IndexedNodeVersion { /// use crate::remote_node_index::list; /// ``` pub fn list(base_url: &Url) -> Result, crate::http::Error> { - let index_json_url = format!("{}/index.json", base_url); + let index_json_url = format!("{base_url}/index.json"); let resp = crate::http::get(&index_json_url)?; let mut value: Vec = resp.json()?; value.sort_by(|a, b| a.version.cmp(&b.version)); diff --git a/src/shell/bash.rs b/src/shell/bash.rs index 64982a1..8f91a68 100644 --- a/src/shell/bash.rs +++ b/src/shell/bash.rs @@ -16,11 +16,11 @@ impl Shell for Bash { let path = path .to_str() .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; - Ok(format!("export PATH={:?}:$PATH", path)) + Ok(format!("export PATH={path:?}:$PATH")) } fn set_env_var(&self, name: &str, value: &str) -> String { - format!("export {}={:?}", name, value) + format!("export {name}={value:?}") } fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result { diff --git a/src/shell/fish.rs b/src/shell/fish.rs index 8856407..078f966 100644 --- a/src/shell/fish.rs +++ b/src/shell/fish.rs @@ -16,11 +16,11 @@ impl Shell for Fish { let path = path .to_str() .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; - Ok(format!("set -gx PATH {:?} $PATH;", path)) + Ok(format!("set -gx PATH {path:?} $PATH;")) } fn set_env_var(&self, name: &str, value: &str) -> String { - format!("set -gx {name} {value:?};", name = name, value = value) + format!("set -gx {name} {value:?};") } fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result { diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index d3c8817..be77c9b 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -22,7 +22,7 @@ impl Shell for PowerShell { } fn set_env_var(&self, name: &str, value: &str) -> String { - format!(r#"$env:{} = "{}""#, name, value) + format!(r#"$env:{name} = "{value}""#) } fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result { diff --git a/src/shell/shell.rs b/src/shell/shell.rs index 45488fa..bd0e320 100644 --- a/src/shell/shell.rs +++ b/src/shell/shell.rs @@ -27,7 +27,7 @@ impl std::str::FromStr for Box { "bash" => Ok(Box::from(super::bash::Bash)), "fish" => Ok(Box::from(super::fish::Fish)), "powershell" => Ok(Box::from(super::powershell::PowerShell)), - shell_type => Err(format!("I don't know the shell type of {:?}", shell_type)), + shell_type => Err(format!("I don't know the shell type of {shell_type:?}",)), } } } diff --git a/src/shell/windows_cmd/mod.rs b/src/shell/windows_cmd/mod.rs index 57faeb3..46e94e6 100644 --- a/src/shell/windows_cmd/mod.rs +++ b/src/shell/windows_cmd/mod.rs @@ -20,11 +20,11 @@ impl Shell for WindowsCmd { let new_path = new_path .to_str() .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; - Ok(format!("SET PATH={}", new_path)) + Ok(format!("SET PATH={new_path}")) } fn set_env_var(&self, name: &str, value: &str) -> String { - format!("SET {}={}", name, value) + format!("SET {name}={value}") } fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result { @@ -39,7 +39,7 @@ impl Shell for WindowsCmd { let path = path .to_str() .ok_or_else(|| anyhow::anyhow!("Can't read path to cd.cmd"))?; - Ok(format!("doskey cd={} $*", path,)) + Ok(format!("doskey cd={path} $*",)) } } diff --git a/src/shell/zsh.rs b/src/shell/zsh.rs index 9bc13ce..44ff557 100644 --- a/src/shell/zsh.rs +++ b/src/shell/zsh.rs @@ -16,11 +16,11 @@ impl Shell for Zsh { let path = path .to_str() .ok_or_else(|| anyhow::anyhow!("Path is not valid UTF-8"))?; - Ok(format!("export PATH={:?}:$PATH", path)) + Ok(format!("export PATH={path:?}:$PATH")) } fn set_env_var(&self, name: &str, value: &str) -> String { - format!("export {}={:?}", name, value) + format!("export {name}={value:?}") } fn rehash(&self) -> Option { diff --git a/src/user_version.rs b/src/user_version.rs index b7524c5..c66d1f1 100644 --- a/src/user_version.rs +++ b/src/user_version.rs @@ -59,8 +59,8 @@ impl std::fmt::Display for UserVersion { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Full(x) => x.fmt(f), - Self::OnlyMajor(major) => write!(f, "v{}.x.x", major), - Self::MajorMinor(major, minor) => write!(f, "v{}.{}.x", major, minor), + Self::OnlyMajor(major) => write!(f, "v{major}.x.x"), + Self::MajorMinor(major, minor) => write!(f, "v{major}.{minor}.x"), } } } diff --git a/src/user_version_reader.rs b/src/user_version_reader.rs index 8c79c7a..6af4605 100644 --- a/src/user_version_reader.rs +++ b/src/user_version_reader.rs @@ -14,8 +14,8 @@ impl UserVersionReader { pub fn into_user_version(self, config: &FnmConfig) -> Option { match self { Self::Direct(uv) => Some(uv), - Self::Path(pathbuf) if pathbuf.is_file() => get_user_version_for_file(&pathbuf), - Self::Path(pathbuf) => get_user_version_for_directory(&pathbuf, config), + Self::Path(pathbuf) if pathbuf.is_file() => get_user_version_for_file(pathbuf), + Self::Path(pathbuf) => get_user_version_for_directory(pathbuf, config), } } } diff --git a/src/version.rs b/src/version.rs index 5c02ab7..35b479d 100644 --- a/src/version.rs +++ b/src/version.rs @@ -53,7 +53,7 @@ impl Version { } pub fn v_str(&self) -> String { - format!("{}", self) + format!("{self}") } pub fn installation_path(&self, config: &config::FnmConfig) -> std::path::PathBuf { @@ -91,9 +91,9 @@ impl std::fmt::Display for Version { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Bypassed => write!(f, "{}", system_version::display_name()), - Self::Lts(lts) => write!(f, "lts-{}", lts), - Self::Semver(semver) => write!(f, "v{}", semver), - Self::Alias(alias) => write!(f, "{}", alias), + Self::Lts(lts) => write!(f, "lts-{lts}"), + Self::Semver(semver) => write!(f, "v{semver}"), + Self::Alias(alias) => write!(f, "{alias}"), Self::Latest => write!(f, "latest"), } }