From 65f8bf7fc5e6d89092a259f8ae05b49b55831737 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Mon, 6 Oct 2025 17:03:06 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(utils):=20implement=20string?= =?UTF-8?q?=20elision=20trait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - introduce `Elide` trait for string truncation - add `elide` function to truncate strings longer than a specified length, adding " ..." at the end --- src/utils.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index bb65739..5225958 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -36,3 +36,19 @@ pub(crate) fn assure_config_dir_exists(dir: &str) -> Result { Ok(expanded_config_dir) } + +pub(crate) trait Elide { + fn elide(&mut self, to: usize) -> &mut Self; +} + +impl Elide for String { + fn elide(&mut self, to: usize) -> &mut Self { + if self.len() <= to { + self + } else { + let range = to - 4; + self.replace_range(range.., " ..."); + self + } + } +}