Expand description
Workspace path helpers: normalization, canonicalization, containment, safety validation, workspace scopes, and ergonomic extension traits.
The implementation lives in focused submodules; everything is re-exported
here so the existing paths:: API is unchanged.
Enums§
- Path
Scope - Enumeration describing the conceptual scope of a file path.
Traits§
- PathExt
- Extension trait that adds path normalization and safety methods to
Path. - Path
Resolver - Helper trait that adds path resolution helpers on top of
WorkspacePaths. - StrPath
Ext - Extension trait that adds path-related methods to
str. - Workspace
Paths - Provides the root directories an application uses to store data.
Functions§
- canonicalize
- Canonicalize a filesystem path without the Windows
\\?\verbatim prefix. - canonicalize_
allow_ missing - Canonicalize a path, walking up to find the nearest existing ancestor for new files.
- canonicalize_
async - Async canonicalize via
dunce, usingspawn_blockingto avoid blocking the runtime. Equivalent totokio::fs::canonicalizebut without the Windows\\?\verbatim prefix. Use this in async contexts instead of the synccanonicalizewhen the path may require I/O. - canonicalize_
workspace - Canonicalize a path with fallback to the original path if canonicalization fails.
- ensure_
path_ within_ workspace - Ensure a candidate path is inside the workspace root after lexical normalization.
- ensure_
path_ within_ workspace_ resolved - Ensure a candidate path is inside the workspace root, resolving symlinks component by component.
- expand_
tilde - Expand a leading
~or~/to the user’s home directory. The function is intentionally forgiving: paths that don’t start with~are returned as-is, and when the home directory cannot be determined the original path is preserved so callers can surface a downstream error rather than panicking. - file_
name_ from_ path - Extract the filename from a path, with fallback to the full path.
- is_
safe_ relative_ path - Check if a path string is a safe relative path (no traversal, no absolute).
- normalize_
ascii_ identifier - Normalize identifiers to ASCII alphanumerics with lowercase output.
- normalize_
path - Normalize a path by resolving
.and..components lexically. - resolve_
workspace_ path - Resolve a path relative to a workspace root and ensure it stays within it.
- safe_
archive_ relative_ path - Validate an archive entry name and return it as a destination-relative path.
- secure_
path - Return a canonicalised absolute path that is guaranteed to reside inside the
provided
workspace_root. If the path is outside the workspace an error is returned. - validate_
no_ escaping_ symlink_ ancestors - Validate every existing path component and reject escaping symlinks.
- validate_
path_ safety - Validates that a path is safe to use. Preventing traversal, absolute system paths, and dangerous characters.
- workspace_
relative_ display - Render a path relative to the workspace when it belongs to that workspace.