path-slash

Tiny Rust library to convert file paths to and from slash paths across platforms.

Library
Cargo
v0.2.1
62stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
32/100Needs Attention
Development Activity0
Maintenance20
Community36
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture78
Code Quality82
Innovation80
Learning Curve90

path-slash is a tiny, dependency-free Rust library for converting file paths to and from “slash paths” — paths whose components are always separated by forward slashes. On Unix-like systems the native separator is already /, but on Windows the separator is \, which must be swapped for / to produce portable, slash-delimited paths (without disturbing escape backslashes).

Inspired by Go’s path/filepath.FromSlash/ToSlash, it extends the standard Path, PathBuf, and Cow<Path> types with ergonomic conversion methods via extension traits, so cross-platform path handling stays idiomatic and allocation-aware.

What You Get

  • Extension traits (PathExt, PathBufExt, CowExt) that add slash-conversion methods to Path, PathBuf, and Cow<Path>
  • to_slash / to_slash_lossy for producing forward-slash string paths on any OS
  • from_slash / from_backslash constructors that build native paths from slash or backslash strings
  • Zero runtime dependencies and a low minimum supported Rust version (1.38.0)

Common Use Cases

  • Normalizing file paths to forward slashes for display, logging, or serialization
  • Building cross-platform tooling that must emit portable slash paths on Windows
  • Round-tripping paths between OS-native and slash representations in build scripts and CLIs

Under The Hood

Architecture - The entire library lives in a single src/lib.rs (~557 lines) that defines three extension traits — PathExt for Path, PathBufExt for PathBuf, and CowExt for Cow<Path> — implemented for the corresponding std types. Conversion logic is cfg-gated on target_os = "windows": on Unix the operations are near pass-throughs returning borrowed Cows, while on Windows separators are rewritten between \ and /. Returning Cow<str>/Cow<Path> lets the API borrow when no allocation is needed and own only when a conversion actually rewrites the path.

Tech Stack - Pure Rust targeting edition 2018 with a minimum supported Rust version of 1.38.0. It has zero runtime dependencies; the only dev-dependency is lazy_static (pinned to 1.4 to preserve the MSRV) used in tests. Built and published through standard Cargo tooling.

Code Quality - The crate is well-tested with dedicated tests/unix.rs and tests/windows.rs integration suites plus doctests embedded in the module documentation, exercising both platform branches. Naming is consistent with std conventions (to_slash, from_slash, lossy variants), and the extensive module-level docs double as executable examples.

API Design - The extension-trait pattern makes adoption a one-line use that grafts slash conversion straight onto existing Path/PathBuf/Cow values, so no wrapper types or boilerplate are needed. Checked (Option-returning) and lossy variants cover both strict and permissive callers, and the API mirrors Go’s familiar FromSlash/ToSlash naming.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search