Skip to content

Commit

Permalink
refactor: simplify is_proxyable_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jan 18, 2024
1 parent 887b8cb commit 1c0c119
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<Vec<_>>()
.join(", ")
)))
.join(", "),
))
}
}

Expand Down

0 comments on commit 1c0c119

Please sign in to comment.