Skip to main content

Crate shrinkpath

Crate shrinkpath 

Source
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§

pub use platform::PathStyle;
pub use strategy::Strategy;

Modules§

path_info
platform
strategy

Structs§

SegmentInfo
Metadata about a single component in the shortened path.
ShrinkOptions
Configuration for path shortening.
ShrinkResult
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).