Skip to main content

truncate_path

Function truncate_path 

Source
pub fn truncate_path(path: &str, max_width: usize) -> String
Expand description

Smart path truncation that preserves the filename.

Guarantee: Output length will NEVER exceed max_width characters.

§Examples

use batuta_common::display::truncate_path;
assert_eq!(truncate_path("/home/user/documents/file.txt", 20), "/home/user…/file.txt");
assert_eq!(truncate_path("/a/b/c.txt", 20), "/a/b/c.txt");