diff --git a/src/context.rs b/src/context.rs index 576f46233..fb8979f11 100644 --- a/src/context.rs +++ b/src/context.rs @@ -225,7 +225,7 @@ impl DirContents { Self::from_path_with_timeout(base, Duration::from_secs(30)) } - fn from_path_with_timeout(base: &PathBuf, timeout: Duration) -> Result { + fn from_path_with_timeout(base: &Path, timeout: Duration) -> Result { let start = Instant::now(); let mut folders: HashSet = HashSet::new(); diff --git a/src/modules/character.rs b/src/modules/character.rs index 4f471406b..dd397ec02 100644 --- a/src/modules/character.rs +++ b/src/modules/character.rs @@ -14,7 +14,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { enum ShellEditMode { Normal, Insert, - }; + } const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert; // TODO: extend config to more modes diff --git a/src/modules/dotnet.rs b/src/modules/dotnet.rs index 29d125a61..4fc71de64 100644 --- a/src/modules/dotnet.rs +++ b/src/modules/dotnet.rs @@ -299,7 +299,7 @@ fn get_latest_sdk_from_cli() -> Option { fn parse_failed() -> Option { log::warn!("Unable to parse the output from `dotnet --list-sdks`."); None - }; + } let latest_sdk = sdks_output .stdout .lines() diff --git a/src/modules/gcloud.rs b/src/modules/gcloud.rs index d04a9e03e..a33daf014 100644 --- a/src/modules/gcloud.rs +++ b/src/modules/gcloud.rs @@ -1,8 +1,8 @@ -use std::collections::HashMap; use std::fs::File; use std::io::{BufRead, BufReader, Error, ErrorKind}; use std::path::PathBuf; use std::str::FromStr; +use std::{collections::HashMap, path::Path}; use super::{Context, Module, RootModuleConfig}; @@ -14,7 +14,7 @@ type Project = String; type Region = String; type Active = String; -fn get_gcloud_account_from_config(current_config: &PathBuf) -> Option { +fn get_gcloud_account_from_config(current_config: &Path) -> Option { let file = File::open(¤t_config).ok()?; let reader = BufReader::new(file); let lines = reader.lines().filter_map(Result::ok); @@ -27,7 +27,7 @@ fn get_gcloud_account_from_config(current_config: &PathBuf) -> Option { Some(account.to_string()) } -fn get_gcloud_project_from_config(current_config: &PathBuf) -> Option { +fn get_gcloud_project_from_config(current_config: &Path) -> Option { let file = File::open(¤t_config).ok()?; let reader = BufReader::new(file); let lines = reader.lines().filter_map(Result::ok); @@ -40,7 +40,7 @@ fn get_gcloud_project_from_config(current_config: &PathBuf) -> Option { Some(project.to_string()) } -fn get_gcloud_region_from_config(current_config: &PathBuf) -> Option { +fn get_gcloud_region_from_config(current_config: &Path) -> Option { let file = File::open(¤t_config).ok()?; let reader = BufReader::new(file); let lines = reader.lines().filter_map(Result::ok); @@ -53,7 +53,7 @@ fn get_gcloud_region_from_config(current_config: &PathBuf) -> Option { Some(region.to_string()) } -fn get_active_config(context: &Context, config_root: &PathBuf) -> Option { +fn get_active_config(context: &Context, config_root: &Path) -> Option { let config_name = context.get_env("CLOUDSDK_ACTIVE_CONFIG_NAME").or_else(|| { let path = config_root.join("active_config"); let file = File::open(&path).ok()?; diff --git a/src/modules/git_state.rs b/src/modules/git_state.rs index aefbc495c..cfd259033 100644 --- a/src/modules/git_state.rs +++ b/src/modules/git_state.rs @@ -1,5 +1,5 @@ use git2::RepositoryState; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use super::{Context, Module, RootModuleConfig}; use crate::configs::git_state::GitStateConfig; @@ -53,7 +53,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { /// During a git operation it will show: REBASING, BISECTING, MERGING, etc. fn get_state_description<'a>( state: RepositoryState, - root: &'a std::path::PathBuf, + root: &'a Path, config: &GitStateConfig<'a>, ) -> Option> { match state { @@ -104,7 +104,7 @@ fn get_state_description<'a>( } } -fn describe_rebase<'a>(root: &'a PathBuf, rebase_config: &'a str) -> StateDescription<'a> { +fn describe_rebase<'a>(root: &'a Path, rebase_config: &'a str) -> StateDescription<'a> { /* * Sadly, libgit2 seems to have some issues with reading the state of * interactive rebases. So, instead, we'll poke a few of the .git files diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index 7c5c13026..e5c59f6c4 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -8,7 +8,7 @@ use regex::Regex; use semver::Version; use semver::VersionReq; use serde_json as json; -use std::path::PathBuf; +use std::path::Path; /// Creates a module with the current Node.js version /// @@ -73,7 +73,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { Some(module) } -fn get_engines_version(base_dir: &PathBuf) -> Option { +fn get_engines_version(base_dir: &Path) -> Option { let json_str = utils::read_file(base_dir.join("package.json")).ok()?; let package_json: json::Value = json::from_str(&json_str).ok()?; let raw_version = package_json.get("engines")?.get("node")?.as_str()?; diff --git a/src/modules/package.rs b/src/modules/package.rs index 0df57c652..e039e4601 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use super::{Context, Module, RootModuleConfig}; use crate::configs::package::PackageConfig; @@ -172,7 +172,7 @@ fn extract_meson_version(file_contents: &str) -> Option { Some(formatted_version) } -fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option { +fn get_package_version(base_dir: &Path, config: &PackageConfig) -> Option { if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) { extract_cargo_version(&cargo_toml) } else if let Ok(package_json) = utils::read_file(base_dir.join("package.json")) { diff --git a/src/modules/php.rs b/src/modules/php.rs index b85341c0b..e7c54e7c6 100644 --- a/src/modules/php.rs +++ b/src/modules/php.rs @@ -42,7 +42,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { _ => None, }) .map(|variable| match variable { - "version" => format_php_version(&php_cmd_output.stdout).map(Ok), + "version" => Some(Ok(format_php_version(&php_cmd_output.stdout))), _ => None, }) .parse(None) @@ -62,11 +62,8 @@ pub fn module<'a>(context: &'a Context) -> Option> { } } -fn format_php_version(php_version: &str) -> Option { - let mut formatted_version = String::with_capacity(php_version.len() + 1); - formatted_version.push('v'); - formatted_version.push_str(php_version); - Some(formatted_version) +fn format_php_version(php_version: &str) -> String { + format!("v{}", php_version) } #[cfg(test)] @@ -80,7 +77,7 @@ mod tests { #[test] fn test_format_php_version() { let input = "7.3.8"; - assert_eq!(format_php_version(input), Some("v7.3.8".to_string())); + assert_eq!(format_php_version(input), "v7.3.8".to_string()); } #[test]