Truncate a string for display.
(s: &str, max_len: usize)
| 728 | |
| 729 | /// Truncate a string for display. |
| 730 | fn truncate(s: &str, max_len: usize) -> String { |
| 731 | if s.len() <= max_len { |
| 732 | s.to_string() |
| 733 | } else { |
| 734 | let truncated: String = s.chars().take(max_len.saturating_sub(3)).collect(); |
| 735 | format!("{}...", truncated) |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | // ============================================================================= |
| 740 | // Tests |