#unix-command #cross-platform #command #unix #which-rs

which

A Rust equivalent of Unix command "which". Locate installed executable in cross platforms.

27 stable releases (7 major)

7.0.0 Nov 1, 2024
6.0.3 Aug 17, 2024
6.0.2 Jul 30, 2024
6.0.1 Mar 22, 2024
0.1.0 Oct 6, 2015

#2 in Operating systems

Download history 1232249/week @ 2024-07-31 1323378/week @ 2024-08-07 1273697/week @ 2024-08-14 1341707/week @ 2024-08-21 1268341/week @ 2024-08-28 1397706/week @ 2024-09-04 1294359/week @ 2024-09-11 1400012/week @ 2024-09-18 1516369/week @ 2024-09-25 1856217/week @ 2024-10-02 1914345/week @ 2024-10-09 1894034/week @ 2024-10-16 1451174/week @ 2024-10-23 1338487/week @ 2024-10-30 1387540/week @ 2024-11-06 1205225/week @ 2024-11-13

5,668,993 downloads per month
Used in 3,321 crates (668 directly)

MIT license

46KB
860 lines

Build Status

which

A Rust equivalent of Unix command "which". Locate installed executable in cross platforms.

Support platforms

  • Linux
  • Windows
  • macOS
  • wasm32-wasi*

A note on WebAssembly

This project aims to support WebAssembly with the wasi extension. This extension is a requirement. which is a library for exploring a filesystem, and WebAssembly without wasi does not have a filesystem. which cannot do anything useful without this extension. Issues and PRs relating to wasm32-unknown-unknown and wasm64-unknown-unknown will not be resolved or merged. All wasm32-wasi* targets are officially supported.

If you need to add a conditional dependency on which for this reason please refer to the relevant cargo documentation for platform specific dependencies.

Here's an example of how to conditionally add which. You should tweak this to your needs.

[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
which = "7.0.0"

Examples

  1. To find which rustc executable binary is using.

    use which::which;
    
    let result = which("rustc").unwrap();
    assert_eq!(result, PathBuf::from("/usr/bin/rustc"));
    
  1. After enabling the regex feature, find all cargo subcommand executables on the path:

    use which::which_re;
    
    which_re(Regex::new("^cargo-.*").unwrap()).unwrap()
        .for_each(|pth| println!("{}", pth.to_string_lossy()));
    

MSRV

This crate currently has an MSRV of Rust 1.70. Increasing the MSRV is considered a breaking change and thus requires a major version bump.

We cannot make any guarantees about the MSRV of our dependencies. You may be required to pin one of our dependencies to a lower version in your own Cargo.toml in order to compile with the minimum supported Rust version. Eventually Cargo will handle this automatically. See rust-lang/cargo#9930 for more.

Documentation

The documentation is available online.

Dependencies

~2–11MB
~137K SLoC