• Home
  • Raw
  • Download

Lines Matching +full:is +full:- +full:binary +full:- +full:path

6 //! To find which rustc executable binary is using:
10 //! use std::path::PathBuf;
27 use std::path;
35 /// Find an executable binary's path by name.
37 /// If given an absolute path, returns it if the file exists and is executable.
39 /// If given a relative path, returns an absolute path to the file if
40 /// it exists and is executable.
42 /// If given a string without path separators, looks for a file named
43 /// `binary_name` at each directory in `$PATH` and if it finds an executable
50 /// use std::path::PathBuf;
56 pub fn which<T: AsRef<OsStr>>(binary_name: T) -> Result<path::PathBuf> { in which()
60 /// Find an executable binary's path by name, ignoring `cwd`.
62 /// If given an absolute path, returns it if the file exists and is executable.
66 /// If given a string without path separators, looks for a file named
67 /// `binary_name` at each directory in `$PATH` and if it finds an executable
74 /// use std::path::PathBuf;
80 pub fn which_global<T: AsRef<OsStr>>(binary_name: T) -> Result<path::PathBuf> { in which_global()
85 pub fn which_all<T: AsRef<OsStr>>(binary_name: T) -> Result<impl Iterator<Item = path::PathBuf>> { in which_all()
92 finder.find(binary_name, env::var_os("PATH"), cwd, binary_checker) in which_all()
98 ) -> Result<impl Iterator<Item = path::PathBuf>> { in which_all_global()
105 env::var_os("PATH"), in which_all_global()
106 Option::<&Path>::None, in which_all_global()
111 /// Find all binaries matching a regular expression in a the system PATH.
113 /// Only available when feature `regex` is enabled.
117 /// * `regex` - A regular expression to match binaries with
126 /// use std::path::PathBuf;
134 /// Find all cargo subcommand executables on the path:
140 /// which_re(Regex::new("^cargo-.*").unwrap()).unwrap()
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()
153 V: AsRef<path::Path>, in which_in() argument
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
167 /// (separated in the same way as the PATH environment variable)
174 /// use std::path::PathBuf;
186 ) -> Result<impl Iterator<Item = path::PathBuf>> 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()
206 V: AsRef<path::Path>, in which_in_all() argument
215 /// Find all binaries with `binary_name` in the path list `paths`, ignoring `cwd`.
219 ) -> Result<impl Iterator<Item = path::PathBuf>> in which_in_global()
228 finder.find(binary_name, paths, Option::<&Path>::None, binary_checker) in which_in_global()
231 fn build_binary_checker() -> CompositeChecker { in build_binary_checker()
239 cwd: Option<either::Either<bool, path::PathBuf>>,
247 fn default() -> Self { in default()
265 pub fn new() -> Self { in new()
274 pub fn system_cwd(mut self, use_cwd: bool) -> Self { in system_cwd()
283 /// Sets a custom path for resolving relative paths.
288 pub fn custom_cwd(mut self, cwd: path::PathBuf) -> Self { 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.
308 pub fn regex(mut self, regex: Regex) -> Self { 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()
340 /// Uses the given string instead of the `PATH` env variable.
341 pub fn custom_path_list(mut self, custom_path_list: OsString) -> Self { in custom_path_list()
346 /// Uses the `PATH` env variable. Enabled by default.
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()
364 let paths = self.custom_path_list.or_else(|| env::var_os("PATH")); in all_results()
370 .map(|i| Box::new(i) as Box<dyn Iterator<Item = path::PathBuf>>); in all_results()
388 .map(|i| Box::new(i) as Box<dyn Iterator<Item = path::PathBuf>>) in all_results()
392 /// An owned, immutable wrapper around a `PathBuf` containing the path of an executable.
394 /// The constructed `PathBuf` is the output of `which` or `which_in`, but `which::Path` has the
395 /// advantage of being a type distinct from `std::path::Path` and `std::path::PathBuf`.
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.
400 /// Since `which::Path` implements `Deref` for `std::path::Path`, all methods on `&std::path::Path`
401 /// are also available to `&which::Path` values.
403 pub struct Path { struct
404 inner: path::PathBuf,
407 impl Path { impl
408 /// Returns the path of an executable binary by name.
410 /// This calls `which` and maps the result into a `Path`.
411 pub fn new<T: AsRef<OsStr>>(binary_name: T) -> Result<Path> { in new() argument
412 which(binary_name).map(|inner| Path { inner }) in new()
417 /// this calls `which_all` and maps the results into `Path`s.
418 pub fn all<T: AsRef<OsStr>>(binary_name: T) -> Result<impl Iterator<Item = Path>> { in all()
419 which_all(binary_name).map(|inner| inner.map(|inner| Path { inner })) in all()
422 /// Returns the path of an executable binary by name in the path list `paths` and using the
425 /// This calls `which_in` and maps the result into a `Path`.
426 pub fn new_in<T, U, V>(binary_name: T, paths: Option<U>, cwd: V) -> Result<Path> in new_in()
430 V: AsRef<path::Path>, in new_in() argument
432 which_in(binary_name, paths, cwd).map(|inner| Path { inner }) in new_in()
435 /// Returns all paths of an executable binary by name in the path list `paths` and using the
438 /// This calls `which_in_all` and maps the results into a `Path`.
443 ) -> Result<impl Iterator<Item = Path>> in all_in()
447 V: AsRef<path::Path>, in all_in() argument
449 which_in_all(binary_name, paths, cwd).map(|inner| inner.map(|inner| Path { inner })) in all_in()
452 /// Returns a reference to a `std::path::Path`.
453 pub fn as_path(&self) -> &path::Path { in as_path() argument
457 /// Consumes the `which::Path`, yielding its underlying `std::path::PathBuf`.
458 pub fn into_path_buf(self) -> path::PathBuf { in into_path_buf()
463 impl fmt::Debug for Path { implementation
464 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
469 impl std::ops::Deref for Path { implementation
470 type Target = path::Path;
472 fn deref(&self) -> &path::Path { in deref() argument
477 impl AsRef<path::Path> for Path { implementation
478 fn as_ref(&self) -> &path::Path { in as_ref() argument
483 impl AsRef<OsStr> for Path { implementation
484 fn as_ref(&self) -> &OsStr { in as_ref()
489 impl PartialEq<path::PathBuf> for Path { implementation
490 fn eq(&self, other: &path::PathBuf) -> bool { in eq()
495 impl PartialEq<Path> for path::PathBuf {
496 fn eq(&self, other: &Path) -> bool { in eq()
501 /// An owned, immutable wrapper around a `PathBuf` containing the _canonical_ path of an
504 /// The constructed `PathBuf` is the result of `which` or `which_in` followed by
505 /// `Path::canonicalize`, but `CanonicalPath` has the advantage of being a type distinct from
506 /// `std::path::Path` and `std::path::PathBuf`.
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
512 /// Since `CanonicalPath` implements `Deref` for `std::path::Path`, all methods on
513 /// `&std::path::Path` are also available to `&CanonicalPath` values.
516 inner: path::PathBuf,
520 /// Returns the canonical path of an executable binary by name.
522 /// This calls `which` and `Path::canonicalize` and maps the result into a `CanonicalPath`.
523 pub fn new<T: AsRef<OsStr>>(binary_name: T) -> Result<CanonicalPath> { in new()
529 /// Returns the canonical paths of an executable binary by name.
531 /// This calls `which_all` and `Path::canonicalize` and maps the results into `CanonicalPath`s.
534 ) -> Result<impl Iterator<Item = Result<CanonicalPath>>> { in all()
545 /// Returns the canonical path of an executable binary by name in the path list `paths` and
548 /// This calls `which_in` and `Path::canonicalize` and maps the result into a `CanonicalPath`.
549 pub fn new_in<T, U, V>(binary_name: T, paths: Option<U>, cwd: V) -> Result<CanonicalPath> in new_in()
553 V: AsRef<path::Path>, in new_in() argument
560 …/// Returns all of the canonical paths of an executable binary by name in the path list `paths` and
563 … /// This calls `which_in_all` and `Path::canonicalize` and maps the result into a `CanonicalPath`.
568 ) -> Result<impl Iterator<Item = Result<CanonicalPath>>> in all_in()
572 V: AsRef<path::Path>, in all_in() argument
584 /// Returns a reference to a `std::path::Path`.
585 pub fn as_path(&self) -> &path::Path { in as_path() argument
589 /// Consumes the `which::CanonicalPath`, yielding its underlying `std::path::PathBuf`.
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()
602 type Target = path::Path;
604 fn deref(&self) -> &path::Path { in deref() argument
609 impl AsRef<path::Path> for CanonicalPath {
610 fn as_ref(&self) -> &path::Path { in as_ref() argument
616 fn as_ref(&self) -> &OsStr { in as_ref()
621 impl PartialEq<path::PathBuf> for CanonicalPath {
622 fn eq(&self, other: &path::PathBuf) -> bool { in eq()
627 impl PartialEq<CanonicalPath> for path::PathBuf {
628 fn eq(&self, other: &CanonicalPath) -> bool { in eq()