✨ feat(utils): implement string elision trait
- introduce `Elide` trait for string truncation - add `elide` function to truncate strings longer than a specified length, adding " ..." at the end
This commit is contained in:
committed by
Jeremiah Russell
parent
f42718328e
commit
65f8bf7fc5
16
src/utils.rs
16
src/utils.rs
@@ -36,3 +36,19 @@ pub(crate) fn assure_config_dir_exists(dir: &str) -> Result<String, Error> {
|
|||||||
|
|
||||||
Ok(expanded_config_dir)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user