Expand description
Cross-platform path expansion, normalization, resolution, traversal, searching, and caching.
path-rs complements std::path::Path and std::path::PathBuf.
It does not replace them.
§Distinguished operations
| Operation | Filesystem access | Requires existence | Resolves symlinks |
|---|---|---|---|
expand_input | No* | No | No |
normalize | No | No | No |
resolve_against | No | No | No |
canonicalize_existing | Yes | Yes | Yes |
path_identity_key | Configurable | No† | Configurable |
app_paths | Platform APIs | No | No |
inspect_directory | Yes | No | Partial |
list / discover_* (feature listing) | Yes | Root yes | Configurable |
search (feature search) | Yes | Root yes | Configurable |
* Home directory resolution may consult environment / platform APIs.
† Unless symlink resolution is enabled on the identity options.
§Architectural boundary
This crate provides generic path mechanics only. Product-specific logic (repository inventories, VCS roots, watchers, cloud remotes, mutation stores) belongs in application adapters that compose these APIs.
§Example
use path_rs::{expand_input, normalize, ExpandOptions};
let expanded = expand_input("~", &ExpandOptions::default()).unwrap();
let normalized = normalize("foo/./bar/../baz").unwrap();
assert_eq!(normalized, std::path::PathBuf::from("foo/baz"));
let _ = expanded;§Security
Lexical normalization is not canonicalization. Lexical root containment is
not symlink-safe. Cached discovery results are not authoritative. Path
identity keys are comparison keys, not filesystem identity proofs. See
SECURITY.md in the repository.
§Feature flags
listing(default): directory listing / discovery (walkdir)search(default): glob and predicate search (globset, implieslisting)persistent-cache: on-disk discovery cache (serde,serde_json)unicode: Unicode NFC logical path keysasync:spawn_blockingwrappers for list/search
§Parallelism
APIs do not spawn threads unless an explicit async helper is used.
Returned types and the in-memory cache are safe to use from parallel callers
(Send + Sync where applicable). The crate does not invoke external
processes, network clients, or VCS tools.
Re-exports§
pub use cache::CacheKey;pub use cache::CacheMode;pub use cache::CacheOptions;pub use cache::CachePolicy;pub use cache::CacheValue;pub use cache::DiscoveryCache;pub use cache::MemoryCache;pub use cache::PersistentCache;persistent-cachepub use discovery::DirectoryVisitor;listingpub use discovery::DiscoveryOptions;listingpub use discovery::VisitControl;listingpub use discovery::discover_directories;listingpub use discovery::discover_where;listingpub use discovery::visit_directories;listingpub use listing::ListOptions;listingpub use listing::WalkIter;listingpub use listing::list;listingpub use listing::walk;listingpub use search::SearchRequest;searchpub use search::search;searchpub use search::search_with;searchpub use search::search_with_cache;search
Modules§
- cache
- Optional discovery caching.
- discovery
listing - Generic recursive directory discovery (no VCS or product-specific roots).
- listing
listing - Directory listing and recursive traversal.
- search
search - Glob and predicate-based path search.
Structs§
- AppPaths
- Application-level platform roots for a named tool.
- AppPaths
Options - Options for resolving
AppPaths. - Command
Line Path Match Options - Options for detecting a path inside a command-line string.
- Directory
Inspection - Result of inspecting a path as a potential directory.
- Executable
Match Options - Options for comparing two executable path strings/paths.
- Expand
Options - Options controlling how user path input is expanded.
- File
Entry - A discovered filesystem entry.
- Metadata
Summary - Summary of filesystem metadata without exposing full
std::fs::Metadata. - Path
Identity Options - Options controlling how a path identity key is produced.
- Path
Record - A path together with optional display text and identity key.
- Platform
Dirs - Platform-standard directories for the current user / process.
- Text
Normalization Options - Options for generic path/token string normalization.
Enums§
- AppRoot
Policy - How to choose the application root.
- Case
Normalization - How to transform letter case in a comparison key or token.
- Entry
Kind - Classification of a filesystem entry.
- Path
Error - Primary error type returned by
path-rsAPIs. - Sort
Mode - Deterministic sort mode for listing and search results.
- Traversal
Error Policy - How to handle I/O errors during traversal.
Functions§
- absolute
- Make
pathabsolute. - app_
paths - Resolve application paths using platform defaults (no directory creation).
- app_
paths_ with_ options - Resolve application paths with explicit options.
- app_
paths_ with_ policy - Resolve paths using an explicit
AppRootPolicy. - cache_
dir - Application-specific cache directory:
{cache}/{app_name}. - canonicalize_
existing - Canonicalize an existing path using the filesystem.
- command_
line_ contains_ path - Returns true if
command_lineappears to referencepath. - config_
dir - Application-specific configuration directory:
{config}/{app_name}. - data_
dir - Application-specific data directory:
{data}/{app_name}. - deduplicate_
paths - Deduplicate paths using identity keys; preserve first occurrence order.
- directory_
exists - Returns
trueifpathexists and is a directory. - ensure_
inside - Normalize both paths and ensure
pathstays insideroot. - executable_
paths_ match - Returns true if two executable paths match under
options. - expand_
dollar_ variables - Expand
$VARand${VAR}style environment variables. - expand_
input - Expand user path input according to
options. - expand_
percent_ variables - Expand
%VAR%style environment variables. - expand_
tilde - Expand a leading
~component to the home directory. - inspect_
directory - Inspect a path without panicking on I/O errors.
- is_
device_ namespace - Returns
trueifpathuses a device namespace prefix (\\.\...). - is_
drive_ relative - Returns
trueifpathis a Windows drive-relative path such asC:fooorC:. - is_
existing_ directory - Alias for
directory_exists. - is_
lexically_ inside - Returns
trueifpathis lexically equal to or beneathroot. - is_
reserved_ windows_ name - Returns
trueifnameis a Windows reserved device name (optionally with extension). - is_unc
- Returns
trueifpathuses a UNC prefix (\\server\shareor verbatim UNC). - is_
verbatim - Returns
trueifpathuses a Windows verbatim prefix (\\?\...). - join_
relative - Join a relative child under
base, rejecting absolute children. - logical_
path_ key unicode - Produce a Unicode-normalized logical key for comparison purposes.
- normalize
- Lexically normalize a path without accessing the filesystem.
- normalize_
path_ token - Normalize a path-like text token for comparison or matching.
- path_
contains_ reserved_ name - Returns
trueif any normal component ofpathis a Windows reserved name. - path_
display_ string - User-facing display string for a path (not an identity key).
- path_
identity_ key - Produce a deterministic path identity / comparison key.
- path_
to_ string_ lossy - Lossy UTF-8 conversion suitable for logs and UI only.
- path_
to_ utf8 - Convert a path to a UTF-8 string slice, or error if it is not valid UTF-8.
- platform_
dirs - Resolve standard platform directories for the current user.
- require_
directory - Require that
pathexists and is a directory; return its path on success. - resolve_
against - Resolve
inputagainstbase. - resolve_
inside - Resolve
childunderroot, ensuring the result stays insiderootlexically. - simplify_
for_ display - Soften a Windows path for display using
dunce(may strip\\?\when safe). - sort_
entries - Apply sorting to a list of entries according to
mode. - temp_
dir - Temporary directory for the process.
- translate_
wsl_ path - Translate a WSL-style
/mnt/<drive>/...path to a Windows path.