thought 2.0.0

Save your thoughts for later.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
pub trait Truncate {
    fn truncate_with_ellipsis(&self, max_width: usize) -> String;
}

impl Truncate for String {
    fn truncate_with_ellipsis(&self, max_width: usize) -> String {
        if self.len() > max_width {
            format!("{}...", &self[..max_width - 3])
        } else {
            self.to_string()
        }
    }
}