fn text_limit_width(text: &str, max_width: usize) -> Cow<str> {
    let text_len = text.chars().count();
    let ellipsis = " ...";

    if text_len <= max_width {
        Cow::from(text)
    } else if max_width < 2 * ellipsis.len() {
        // It does not make sense to insert ellipsis if there is less space than
        // the space the ellipsis will take themselves, so we just cut in this
        // case.
        let up_to = str_byte_pos(text, max_width);
        Cow::from(&text[0..up_to])
    } else {
        let up_to = str_byte_pos(text, max_width - ellipsis.len());
        Cow::from(text[0..up_to].to_string() + ellipsis)
    }
}
/// Makes sure that a string does not exceed the specified width.  If it
/// does, cuts the string to make it fit, adding ' ...' at the end.
Makes sure that a string does not exceed the specified width.  If it
does, cuts the string to make it fit, adding ' ...' at the end.
Makes sure that a string does not exceed the specified width . If it does cuts the string to make it fit adding ' ... ' at the end .
fn text_limit_width(text: &str, max_width: usize) -> Cow<str> {
    let text_len = text.chars().count();
    let ellipsis = " ...";
    if text_len <= max_width {
        Cow::from(text)
    } else if max_width < 2 * ellipsis.len() {
        // It does not make sense to insert ellipsis if there is less space than
        // the space the ellipsis will take themselves, so we just cut in this
        // case.
        let up_to = str_byte_pos(text, max_width);
        Cow::from(&text[0..up_to])
    } else {
        let up_to = str_byte_pos(text, max_width - ellipsis.len());
        Cow::from(text[0..up_to].to_string() + ellipsis)
    }
}
fn text_limit_width ( text : & str , max_width : usize ) -> Cow < str > { let text_len = text . chars ( ) . count ( ) ; let ellipsis = " " ; if text_len <= max_width { Cow :: from ( text ) } else if max_width < 2 * ellipsis . len ( ) { // It does not make sense to insert ellipsis if there is less space than // the space the ellipsis will take themselves, so we just cut in this // case. let up_to = str_byte_pos ( text , max_width ) ; Cow :: from ( & text [ 0 .. up_to ] ) } else { let up_to = str_byte_pos ( text , max_width - ellipsis . len ( ) ) ; Cow :: from ( text [ 0 .. up_to ] . to_string ( ) + ellipsis ) } }
Makes sure that a string does not exceed the specified width.
Makes sure that a string does not exceed the specified width .
text
&str
max_width
usize