Function fold_string

Source
pub fn fold_string<F>(
    val: &str,
    width: usize,
    start_idx: usize,
    stop_filter: F,
) -> String
where F: FnMut(char) -> bool,
Expand description

Fold a long string to a fixed size string and keep the front and back

The effective length of the string will be width - 3 since this fn will use 3 ’.’s to replace the omitted content. If the width is less than 3, it will return the original string. This function will also take a stop_filter closure as an indicator of where to split the string. Please note that, this function will take the minimal value of (width - 3)/2 and first index that hit the stop_filter as the front half cutting point.

§Arguments

  • val – The string that needs to be folded.
  • width – The final target string length.
  • start_idx – From which index should we start apply the stop_filter
  • stop_filter – The first half will be cut at the first index that returns false after apply the filter if the index is less than (width - 3)/2