Lines Matching +full:to +full:- +full:regex
6 //! To find which rustc executable binary is using:
23 #[cfg(feature = "regex")]
39 /// If given a relative path, returns an absolute path to the file if
56 pub fn which<T: AsRef<OsStr>>(binary_name: T) -> Result<path::PathBuf> { in which()
80 pub fn which_global<T: AsRef<OsStr>>(binary_name: T) -> Result<path::PathBuf> { in which_global()
84 /// Find all binaries with `binary_name` using `cwd` to resolve relative paths.
85 pub fn which_all<T: AsRef<OsStr>>(binary_name: T) -> Result<impl Iterator<Item = path::PathBuf>> { in which_all()
98 ) -> Result<impl Iterator<Item = path::PathBuf>> { in which_all_global()
113 /// Only available when feature `regex` is enabled.
117 /// * `regex` - A regular expression to match binaries with
124 /// use regex::Regex;
128 /// let re = Regex::new(r"python\d$").unwrap();
138 /// use regex::Regex;
140 /// which_re(Regex::new("^cargo-.*").unwrap()).unwrap()
143 #[cfg(feature = "regex")]
144 pub fn which_re(regex: impl Borrow<Regex>) -> Result<impl Iterator<Item = path::PathBuf>> { in which_re()
145 which_re_in(regex, env::var_os("PATH")) in which_re()
148 /// Find `binary_name` in the path list `paths`, using `cwd` to resolve relative paths.
149 pub fn which_in<T, U, V>(binary_name: T, paths: Option<U>, cwd: V) -> Result<path::PathBuf> in which_in()
161 /// Only available when feature `regex` is enabled.
165 /// * `regex` - A regular expression to match binaries with
166 /// * `paths` - A string containing the paths to search
172 /// use regex::Regex;
176 /// let re = Regex::new(r"python\d$").unwrap();
182 #[cfg(feature = "regex")]
184 regex: impl Borrow<Regex>, in which_re_in() argument
186 ) -> Result<impl Iterator<Item = path::PathBuf>> in which_re_in()
194 finder.find_re(regex, paths, binary_checker) in which_re_in()
197 /// Find all binaries with `binary_name` in the path list `paths`, using `cwd` to resolve relative …
202 ) -> Result<impl Iterator<Item = path::PathBuf>> in which_in_all()
219 ) -> Result<impl Iterator<Item = path::PathBuf>> in which_in_global()
231 fn build_binary_checker() -> CompositeChecker { in build_binary_checker()
242 #[cfg(feature = "regex")]
243 regex: Option<Regex>, field
247 fn default() -> Self { in default()
252 #[cfg(feature = "regex")] in default()
253 regex: None, in default()
258 #[cfg(feature = "regex")]
259 type Regex = regex::Regex; typedef
261 #[cfg(not(feature = "regex"))]
262 type Regex = (); typedef
265 pub fn new() -> Self { in new()
269 /// Whether or not to use the current working directory. `true` by default.
273 /// If regex was set previously, and you've just passed in `use_cwd: true`, this will panic.
274 pub fn system_cwd(mut self, use_cwd: bool) -> Self { in system_cwd()
275 #[cfg(feature = "regex")] in system_cwd()
276 if self.regex.is_some() && use_cwd { in system_cwd()
277 panic!("which can't use regex and cwd at the same time!") in system_cwd()
287 /// If regex was set previously, this will panic.
288 pub fn custom_cwd(mut self, cwd: path::PathBuf) -> Self { in custom_cwd()
289 #[cfg(feature = "regex")] in custom_cwd()
290 if self.regex.is_some() { in custom_cwd()
291 panic!("which can't use regex and cwd at the same time!") in custom_cwd()
297 …/// Sets the path name regex to search for. You ***MUST*** call this, or [`Self::binary_name`] pri…
299 …/// When `Regex` is disabled this function takes the unit type as a stand in. The parameter will c…
300 /// `Regex` is enabled.
304 …/// If the `regex` feature wasn't turned on for this crate this will always panic. Additionally if…
306 /// are incompatible with `regex`.
308 pub fn regex(mut self, regex: Regex) -> Self { in regex() method
309 #[cfg(not(feature = "regex"))] in regex()
311 panic!("which's regex feature was not enabled in your Cargo.toml!") in regex()
313 #[cfg(feature = "regex")] in regex()
316 panic!("which can't use regex and cwd at the same time!") in regex()
319 panic!("which can't use `binary_name` and `regex` at the same time!"); in regex()
321 self.regex = Some(regex); in regex()
326 …/// Sets the path name to search for. You ***MUST*** call this, or [`Self::regex`] prior to search…
330 /// If a `regex` was set previously this will panic as this is not compatible with `regex`.
331 pub fn binary_name(mut self, name: OsString) -> Self { in binary_name()
332 #[cfg(feature = "regex")] in binary_name()
333 if self.regex.is_some() { in binary_name()
334 panic!("which can't use `binary_name` and `regex` at the same time!"); in binary_name()
341 pub fn custom_path_list(mut self, custom_path_list: OsString) -> Self { in custom_path_list()
347 pub fn system_path_list(mut self) -> Self { in system_path_list()
353 pub fn first_result(self) -> Result<path::PathBuf> { in first_result()
359 pub fn all_results(self) -> Result<impl Iterator<Item = path::PathBuf>> { in all_results()
366 #[cfg(feature = "regex")] in all_results()
367 if let Some(regex) = self.regex { in all_results()
369 .find_re(regex, paths, binary_checker) in all_results()
382 "binary_name not set! You must set binary_name or regex before searching!", in all_results()
397 /// It can be beneficial to use `which::Path` instead of `std::path::Path` when you want the type
398 /// system to enforce the need for a path that exists and points to a binary that is executable.
401 /// are also available to `&which::Path` values.
411 pub fn new<T: AsRef<OsStr>>(binary_name: T) -> Result<Path> { in new()
418 pub fn all<T: AsRef<OsStr>>(binary_name: T) -> Result<impl Iterator<Item = Path>> { in all()
423 /// current working directory `cwd` to resolve relative paths.
426 pub fn new_in<T, U, V>(binary_name: T, paths: Option<U>, cwd: V) -> Result<Path> in new_in()
436 /// current working directory `cwd` to resolve relative paths.
443 ) -> Result<impl Iterator<Item = Path>> in all_in()
452 /// Returns a reference to a `std::path::Path`.
453 pub fn as_path(&self) -> &path::Path { in as_path()
458 pub fn into_path_buf(self) -> path::PathBuf { in into_path_buf()
464 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
472 fn deref(&self) -> &path::Path { in deref()
478 fn as_ref(&self) -> &path::Path { in as_ref()
484 fn as_ref(&self) -> &OsStr { in as_ref()
490 fn eq(&self, other: &path::PathBuf) -> bool { in eq()
496 fn eq(&self, other: &Path) -> bool { in eq()
508 /// It can be beneficial to use `CanonicalPath` instead of `std::path::Path` when you want the type
509 /// system to enforce the need for a path that exists, points to a binary that is executable, is
513 /// `&std::path::Path` are also available to `&CanonicalPath` values.
523 pub fn new<T: AsRef<OsStr>>(binary_name: T) -> Result<CanonicalPath> { in new()
534 ) -> Result<impl Iterator<Item = Result<CanonicalPath>>> { in all()
546 /// using the current working directory `cwd` to resolve relative paths.
549 pub fn new_in<T, U, V>(binary_name: T, paths: Option<U>, cwd: V) -> Result<CanonicalPath> in new_in()
561 /// using the current working directory `cwd` to resolve relative paths.
568 ) -> Result<impl Iterator<Item = Result<CanonicalPath>>> in all_in()
584 /// Returns a reference to a `std::path::Path`.
585 pub fn as_path(&self) -> &path::Path { in as_path()
590 pub fn into_path_buf(self) -> path::PathBuf { in into_path_buf()
596 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
604 fn deref(&self) -> &path::Path { in deref()
610 fn as_ref(&self) -> &path::Path { in as_ref()
616 fn as_ref(&self) -> &OsStr { in as_ref()
622 fn eq(&self, other: &path::PathBuf) -> bool { in eq()
628 fn eq(&self, other: &CanonicalPath) -> bool { in eq()