From 0a72c68e38312bfe802bc7792afbcb933a27e175 Mon Sep 17 00:00:00 2001 From: rami3l Date: Thu, 18 Jan 2024 18:06:51 +0800 Subject: [PATCH] refactor: simplify `is_proxyable_tools` --- src/lib.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index af9875c969..b5215ea09f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub use crate::errors::*; pub(crate) use crate::notifications::*; pub(crate) use crate::utils::toml_utils; use anyhow::{anyhow, Result}; +use itertools::{chain, Itertools}; #[macro_use] extern crate rs_tracing; @@ -41,23 +42,15 @@ pub static DUP_TOOLS: &[&str] = &["rust-analyzer", "rustfmt", "cargo-fmt"]; // If the given name is one of the tools we proxy. pub fn is_proxyable_tools(tool: &str) -> Result<()> { - if TOOLS - .iter() - .chain(DUP_TOOLS.iter()) - .any(|&name| name == tool) - { + if chain!(TOOLS, DUP_TOOLS).contains(&tool) { Ok(()) } else { - Err(anyhow!(format!( - "unknown proxy name: '{}'; valid proxy names are {}", - tool, - TOOLS - .iter() - .chain(DUP_TOOLS.iter()) + Err(anyhow!( + "unknown proxy name: '{tool}'; valid proxy names are {}", + chain!(TOOLS, DUP_TOOLS) .map(|s| format!("'{s}'")) - .collect::>() - .join(", ") - ))) + .join(", "), + )) } }