Skip to main content

truncate

Function truncate 

Source
pub fn truncate(s: &str, max_width: usize, strategy: TruncateStrategy) -> String
Expand description

Truncate a string to fit within a maximum width.

Guarantee: Output length will NEVER exceed max_width characters.

§Examples

use batuta_common::display::{truncate, TruncateStrategy};
assert_eq!(truncate("hello world", 8, TruncateStrategy::End), "hello w…");
assert_eq!(truncate("hello world", 8, TruncateStrategy::Start), "…o world");
assert_eq!(truncate("hello world", 8, TruncateStrategy::Middle), "hel…orld");
assert_eq!(truncate("short", 10, TruncateStrategy::End), "short");