Expand description
§shrinkpath
Smart, cross-platform path shortening for Rust.
Intelligently shortens file paths while preserving the information that matters most: the filename (never truncated) and the user identity (preserved when possible).
§Quick Start
use shrinkpath::{shrink_to, shrink_fish};
// Hybrid strategy with target length
let short = shrink_to("/home/john/projects/rust/myapp/src/lib.rs", 30);
assert!(short.len() <= 30);
assert!(short.ends_with("lib.rs"));
// Fish-style abbreviation (no length target)
let fish = shrink_fish("/home/john/projects/rust/myapp/src/lib.rs");
assert_eq!(fish, "/h/j/p/r/m/s/lib.rs");§Strategies
- Hybrid (default): Graduated approach — abbreviates expendable segments first,
then context segments, then collapses runs into
..., then abbreviates identity. - Fish: Abbreviates every directory segment to its first character.
- Ellipsis: Replaces middle segments with
..., keeping identity and tail.
§Platform Support
Handles Windows (C:\Users\..., UNC \\server\share\..., .\...),
macOS (/Users/...), and Linux (/home/...) paths. Auto-detects the style
from the input string, or you can force it with PathStyle.
Re-exports§
Modules§
Structs§
- Segment
Info - Metadata about a single component in the shortened path.
- Shrink
Options - Configuration for path shortening.
- Shrink
Result - Result of a shrink operation with metadata.
Functions§
- shrink
- Shorten a path using the given options.
- shrink_
detailed - Shorten a path with detailed result metadata.
- shrink_
ellipsis - Shorten a path using ellipsis with a target max length.
- shrink_
fish - Shorten a path using Fish-style abbreviation (no length target).
- shrink_
to - Shorten a path using the Hybrid strategy with a target max length.
- shrink_
unique - Shorten a path using unique-prefix disambiguation (no length target).