Crates.io | pathx |
lib.rs | pathx |
version | 0.1.0 |
created_at | 2025-08-29 19:08:04.584307+00 |
updated_at | 2025-08-29 19:08:04.584307+00 |
description | A collection of utilities for working with paths. |
homepage | https://github.com/Pjdur/pathx |
repository | https://github.com/Pjdur/pathx |
max_upload_size | |
id | 1816364 |
size | 27,115 |
A collection of ergonomic, cross-platform utilities for working with paths in Rust.
From lexical normalization to templated path generation, pathx
helps you compose, analyze, and manipulate paths with clarity and precision.
join()
— Join and normalize paths lexicallynormalize()
— Resolve .
and ..
without touching the filesystemrelative_to()
— Compute relative paths between two locationstemplate!()
— Rust-style macro for path templatingis_subpath()
— Check if one path is lexically nested under anotherstrip_root()
— Remove root or prefix from a pathseparator()
All utilities are pure, lexical, and cross-platform safe.
Add to your Cargo.toml
:
[dependencies]
pathx = "0.1.0"
use pathx::join;
use std::path::Path;
let base = Path::new("/foo/bar");
let segment = Path::new("../baz");
let path = join(base, segment).unwrap();
// → "/foo/baz"
use pathx::template;
let path = template!("src/{module}/{file}.rs", {
module: "utils",
file: "normalize"
});
// → "src/utils/normalize.rs"
use pathx::relative_to;
use std::path::Path;
let base = Path::new("/a/b/c");
let target = Path::new("/a/b/d/e.txt");
let rel = relative_to(base, target);
// → "../d/e.txt"
Function / Macro | Description |
---|---|
join(base, segment) |
Joins and normalizes two paths |
join_lossy(...) |
Same as join , but falls back on error |
normalize(path) |
Lexically resolves . and .. |
normalize_lossy(...) |
Returns original path if normalization fails |
relative_to(base, target) |
Computes relative path from base to target |
is_subpath(base, child) |
Checks if child is nested under base |
strip_root(path) |
Removes root or prefix from a path |
template!(...) |
Macro for path templating using {key} syntax |
render_template(...) |
Function version of template!() |
separator() |
Returns platform-specific path separator |
All path operations are lexical only — no filesystem access or symlink resolution.
Contributions, bug reports, and feature requests are welcome!
Please follow Rust’s formatting and documentation conventions.
Licensed under the MIT License.
You’re free to use, modify, and distribute this crate with attribution.
Created by Pjdur.
Feel free to reach out or open an issue if you have ideas or feedback!