Lines Matching full:path

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
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> {
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> {
85 pub fn which_all<T: AsRef<OsStr>>(binary_name: T) -> Result<impl Iterator<Item = path::PathBuf>> {
92 finder.find(binary_name, env::var_os("PATH"), cwd, binary_checker)
98 ) -> Result<impl Iterator<Item = path::PathBuf>> {
105 env::var_os("PATH"),
106 Option::<&Path>::None,
111 /// Find all binaries matching a regular expression in a the system PATH.
126 /// use std::path::PathBuf;
134 /// Find all cargo subcommand executables on the path:
144 pub fn which_re(regex: impl Borrow<Regex>) -> Result<impl Iterator<Item = path::PathBuf>> {
145 which_re_in(regex, env::var_os("PATH"))
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>
153 V: AsRef<path::Path>,
167 /// (separated in the same way as the PATH environment variable)
174 /// use std::path::PathBuf;
186 ) -> Result<impl Iterator<Item = path::PathBuf>>
197 /// Find all binaries with `binary_name` in the path list `paths`, using `cwd` to resolve relative paths.
202 ) -> Result<impl Iterator<Item = path::PathBuf>>
206 V: AsRef<path::Path>,
215 /// Find all binaries with `binary_name` in the path list `paths`, ignoring `cwd`.
219 ) -> Result<impl Iterator<Item = path::PathBuf>>
228 finder.find(binary_name, paths, Option::<&Path>::None, binary_checker)
239 cwd: Option<either::Either<bool, path::PathBuf>>,
283 /// Sets a custom path for resolving relative paths.
288 pub fn custom_cwd(mut self, cwd: path::PathBuf) -> Self {
297 /// Sets the path name regex to search for. You ***MUST*** call this, or [`Self::binary_name`] prior to searching.
326 /// Sets the path name to search for. You ***MUST*** call this, or [`Self::regex`] prior to searching.
340 /// Uses the given string instead of the `PATH` env variable.
346 /// Uses the `PATH` env variable. Enabled by default.
353 pub fn first_result(self) -> Result<path::PathBuf> {
359 pub fn all_results(self) -> Result<impl Iterator<Item = path::PathBuf>> {
364 let paths = self.custom_path_list.or_else(|| env::var_os("PATH"));
370 .map(|i| Box::new(i) as Box<dyn Iterator<Item = path::PathBuf>>);
388 .map(|i| Box::new(i) as Box<dyn Iterator<Item = path::PathBuf>>)
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 {
404 inner: path::PathBuf,
407 impl Path {
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> {
412 which(binary_name).map(|inner| Path { inner })
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>> {
419 which_all(binary_name).map(|inner| inner.map(|inner| Path { inner }))
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>
430 V: AsRef<path::Path>,
432 which_in(binary_name, paths, cwd).map(|inner| Path { inner })
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>>
447 V: AsRef<path::Path>,
449 which_in_all(binary_name, paths, cwd).map(|inner| inner.map(|inner| Path { inner }))
452 /// Returns a reference to a `std::path::Path`.
453 pub fn as_path(&self) -> &path::Path {
457 /// Consumes the `which::Path`, yielding its underlying `std::path::PathBuf`.
458 pub fn into_path_buf(self) -> path::PathBuf {
463 impl fmt::Debug for Path {
469 impl std::ops::Deref for Path {
470 type Target = path::Path;
472 fn deref(&self) -> &path::Path {
477 impl AsRef<path::Path> for Path {
478 fn as_ref(&self) -> &path::Path {
483 impl AsRef<OsStr> for Path {
489 impl PartialEq<path::PathBuf> for Path {
490 fn eq(&self, other: &path::PathBuf) -> bool {
495 impl PartialEq<Path> for path::PathBuf {
496 fn eq(&self, other: &Path) -> bool {
501 /// An owned, immutable wrapper around a `PathBuf` containing the _canonical_ path of an
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`.
531 /// This calls `which_all` and `Path::canonicalize` and maps the results into `CanonicalPath`s.
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`.
553 V: AsRef<path::Path>,
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`.
572 V: AsRef<path::Path>,
584 /// Returns a reference to a `std::path::Path`.
585 pub fn as_path(&self) -> &path::Path {
589 /// Consumes the `which::CanonicalPath`, yielding its underlying `std::path::PathBuf`.
590 pub fn into_path_buf(self) -> path::PathBuf {
602 type Target = path::Path;
604 fn deref(&self) -> &path::Path {
609 impl AsRef<path::Path> for CanonicalPath {
610 fn as_ref(&self) -> &path::Path {
621 impl PartialEq<path::PathBuf> for CanonicalPath {
622 fn eq(&self, other: &path::PathBuf) -> bool {
627 impl PartialEq<CanonicalPath> for path::PathBuf {