| Crates.io | search_path |
| lib.rs | search_path |
| version | 0.1.4 |
| created_at | 2021-07-16 23:13:13.593004+00 |
| updated_at | 2022-10-20 15:42:26.984983+00 |
| description | Provides a very simple search path file finder. |
| homepage | |
| repository | https://github.com/johnstonskj/rust-search_path.git |
| max_upload_size | |
| id | 423800 |
| size | 28,416 |
Provides a very simple search path file finder.
The SearchPath type allows for the finding of files using a series of search directories. This is
akin to the mechanism a shell uses to find executables using the PATH environment variable. It
can be constructed with a search path from an environment variable, from a string, or from a list
of either string or Path/PathBuf values. Typically the find methods return the first
matching file or directory, but the find_all method specifically collects and returns a list of
all matching paths.
The SearchPath type also has From<> implementations for PathBuf, Vec<PathBuf>, Vec<&Path>,
Vec<&str>, String, and &str. In the case of vector values, or a single PathBuf, each path
value will be used as-is without trying to split it into components. In the case of individual
String and &str values the value will be split using the platform specific path separator
into individual paths components.
The following example shows the common pattern of finding an executable command on the command line.
use search_path::SearchPath;
use std::path::PathBuf;
fn which_command(cmd_name: &str) -> Option<PathBuf> {
let search_path = SearchPath::new("PATH").unwrap();
search_path.find_file(&PathBuf::from(cmd_name))
}
Version 0.1.4
path as a simple shortcut.Version 0.1.3
Version 0.1.2
Version 0.1.1
Version 0.1.0