Function which::which_re_in
source · pub fn which_re_in<T>(
regex: impl Borrow<Regex>,
paths: Option<T>
) -> Result<impl Iterator<Item = PathBuf>>
Expand description
Find all binaries matching a regular expression in a list of paths.
Only available when feature regex
is enabled.
§Arguments
regex
- A regular expression to match binaries withpaths
- A string containing the paths to search (separated in the same way as the PATH environment variable)
§Examples
use regex::Regex;
use which::which;
use std::path::PathBuf;
let re = Regex::new(r"python\d$").unwrap();
let paths = Some("/usr/bin:/usr/local/bin");
let binaries: Vec<PathBuf> = which::which_re_in(re, paths).unwrap().collect();
let python_paths = vec![PathBuf::from("/usr/bin/python2"), PathBuf::from("/usr/bin/python3")];
assert_eq!(binaries, python_paths);