pub struct StrFit { /* private fields */ }
Expand description
Information about the fitting of a string into a given width in cols.
The implementation here properly takes into account the width of special characters.
Backspaces are considered as having a width of -1.
This implementation is based on a replacement of the tab character.
Implementations§
source§impl StrFit
impl StrFit
pub fn from(s: &str, cols_max: usize) -> Self
sourcepub fn count_fitting(s: &str, cols_max: usize) -> (usize, usize)
pub fn count_fitting(s: &str, cols_max: usize) -> (usize, usize)
return the counts in bytes and columns of the longest substring fitting the given number of columns
sourcepub fn make_string(s: &str, cols_max: usize) -> (String, usize)
pub fn make_string(s: &str, cols_max: usize) -> (String, usize)
return both the longest fitting string and the number of cols it takes on screen.
We don’t build a string around the whole str, which could be costly if it’s very big
sourcepub fn make_cow(s: &str, cols_max: usize) -> (Cow<'_, str>, usize)
pub fn make_cow(s: &str, cols_max: usize) -> (Cow<'_, str>, usize)
return both the longest fitting string and the number of cols it takes on screen.
We don’t build a string around the whole str, which could be costly if it’s very big In case there’s no tab in the input string, we can return a pointer over part of the original str)