Crates.io | find-in-path |
lib.rs | find-in-path |
version | 1.0.0 |
source | src |
created_at | 2023-10-11 17:44:50.625793 |
updated_at | 2023-10-11 17:44:50.625793 |
description | Initialize a LaTex project inside a folder instantly |
homepage | |
repository | |
max_upload_size | |
id | 1000450 |
size | 47,728 |
This is a rust crate that aims to find an executable in the user's PATH.
Using this crate is very simple.
All you need to do is use find_in_path::prelude::*;
or use find_in_path::FindInPath;
to be able to find a String
, &str
, PathBuf
, &Path
in the user's PATH.
use find_in_path::prelude::*;
use std::path::PathBuf;
let s: String = "sysctl".to_string();
let s_in_path: Option<PathBuf> = s.find_in_path();
// The resultant path will be os and distribution specific
#[cfg(unix)]
assert_eq!(s_in_path, Some(PathBuf::from("/usr/sbin/sysctl")));
#[cfg(windows)]
assert_eq!(s_in_path, None);
find_in_path will support non-unicode paths through the OsString and &OsStr methods, however this remains unimplemented until a future release.
By default FindInPath
delays looking in relative directories found in the PATH until the end, because this may lead to unwanted executables being run.
You can stop FindInPath from checking relative directories altogether by setting the "skip_relative_directories" cargo feature.
Additionally, if the path to the file found in a relative path, the returned PathBuf
will always be relative.
By default this crate assumes you are looking for an executable, which means that it will skip anything that is not an executable.
On Windows you can activate the non-default add_exe_ext
cargo feature in order to automatically add .exe to the end of filenames if there isn't one there already.
The feature will also not append .exe
if the filename ends in .dll
.
find_in_path = { version = "VERSION_NUMBER", features = ["add_exe_ext"] }
Setting this feature on unix does nothing.