path_normalizer 0.1.1

Lexically normalize paths in Rust without touching the filesystem.
Documentation

path_normalizer

Crates.io Docs.rs CI License: MIT

๐Ÿงน A lightweight Rust crate for lexically normalizing paths โ€” no filesystem access required.

Why?

This crate is useful for scenarios where you need to manipulate or validate paths without relying on the filesystem. It's particularly handy for:

  • Virtual Filesystems: When working with in-memory or virtual filesystems, you can't rely on actual paths existing on disk.
  • Configuration Parsing: When reading configuration files, you may need to normalize paths specified by users.
  • Sandboxed Environments: In environments where filesystem access is restricted, you can still perform path manipulations.

Note: The features of this crate exist in the Rust standard libary (std), but only on the nightly toolchain. This crate provides its features but available regardless of Rust toolchain.

โœจ Features

  • Normalize paths like "foo/./bar/../baz" to "foo/baz"
  • Works purely on string logic โ€” doesn't touch the filesystem
  • Cross-platform and fast

๐Ÿ“ฆ Installation

Add this to your Cargo.toml:

[dependencies]
path_normalizer = "0.1"

๐Ÿš€ Usage

use path_normalizer::PathNormalizeExt;
use std::path::Path;

fn main() {
    let path = Path::new("foo/./bar/../baz");
    let normalized = path.normalize_path().unwrap();
    println!("Normalized: {}", normalized.display()); // Outputs: foo/baz
}

๐Ÿ”’ Why Lexical?

Unlike canonicalize(), this crate doesn't resolve symlinks or check the filesystem. It simply rewrites the path using lexical rules โ€” making it ideal for virtual paths, config parsing, or sandboxed environments.

๐Ÿ“š License

MIT


Made with โค๏ธ for Rustaceans who like their paths tidy.