Skip to main content

truncate_path

Function truncate_path 

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

Truncate a path from the beginning, respecting UTF-8 char boundaries.

Unlike truncate_str, this keeps the end of the string (which typically contains the filename) and truncates from the beginning.

§Examples

assert_eq!(truncate_path("/very/long/path/to/file.rs", 15), "...to/file.rs");
assert_eq!(truncate_path("short.rs", 20), "short.rs");