Unix which utility in pure Rust
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jacob Kiesel 5bb3e82a82
Some checks failed
Main workflow / cargo-deny (push) Has been cancelled
Main workflow / Rustfmt [Formatter] (push) Has been cancelled
Main workflow / Clippy [Linter] (push) Has been cancelled
Main workflow / Clippy [Linter]-1 (push) Has been cancelled
Main workflow / Clippy [Linter]-2 (push) Has been cancelled
Main workflow / Compile (push) Has been cancelled
Main workflow / Compile-1 (push) Has been cancelled
Main workflow / Compile-2 (push) Has been cancelled
Main workflow / Test Suite-6 (push) Has been cancelled
Main workflow / Test Suite-7 (push) Has been cancelled
Main workflow / Test Suite-8 (push) Has been cancelled
Main workflow / Test Suite (push) Has been cancelled
Main workflow / Test Suite-1 (push) Has been cancelled
Main workflow / Test Suite-2 (push) Has been cancelled
Main workflow / Test Suite-3 (push) Has been cancelled
Main workflow / Test Suite-4 (push) Has been cancelled
Main workflow / Test Suite-5 (push) Has been cancelled
update README MSRV
2026-03-08 13:08:40 -06:00
.github/workflows New windows impl (#121) 2026-03-08 12:05:33 -06:00
src Swap dependency on rustix for dependency on libc (#122) 2026-03-08 13:00:40 -06:00
tests Swap dependency on rustix for dependency on libc (#122) 2026-03-08 13:00:40 -06:00
.gitignore check in Cargo.lock which is compatible with Rust 1.70 2026-03-04 23:33:20 -07:00
Cargo.lock Swap dependency on rustix for dependency on libc (#122) 2026-03-08 13:00:40 -06:00
Cargo.toml Swap dependency on rustix for dependency on libc (#122) 2026-03-08 13:00:40 -06:00
CHANGELOG.md add changelog entry 2026-03-08 13:06:38 -06:00
clippy.toml clippy fixes 2026-03-07 10:29:13 -07:00
deny.toml modernize deny.toml 2024-07-29 18:02:30 -06:00
LICENSE.txt init commit 2015-10-06 19:24:01 +08:00
README.md update README MSRV 2026-03-08 13:08:40 -06:00
RELEASE_STEPS.md chore: add release steps documentation 2026-03-05 21:50:51 -07:00

Build Status Actively Maintained

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. All wasm32-wasi* targets are officially supported.

If you need to add a conditional dependency on which 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 = "8.0.0"

Note that non-WASI environments have no access to the system. Using this in that situation requires disabling the default features of this crate and providing a custom which::sys::Sys implementation to which::WhichConfig.

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.