Function truncate_message

Source
pub(crate) fn truncate_message(s: &str, max_chars: usize) -> String
Expand description

Truncates a message to a specified maximum length for display purposes.

This utility function is used to create abbreviated versions of messages for status displays and logs where space is limited.

§Arguments

  • s - The string to truncate
  • max_chars - Maximum number of characters to include

§Returns

  • String - The truncated string with “…” suffix if truncation occurred

§Examples

let short = truncate_message("Hello world", 5);
assert_eq!(short, "He...");

let unchanged = truncate_message("Hi", 10);
assert_eq!(unchanged, "Hi");