pub trait UnicodeTruncateStr {
// Required methods
fn unicode_truncate(&self, max_width: usize) -> (&str, usize);
fn unicode_truncate_start(&self, max_width: usize) -> (&str, usize);
fn unicode_truncate_centered(&self, max_width: usize) -> (&str, usize);
fn unicode_pad(
&self,
target_width: usize,
align: Alignment,
truncate: bool,
) -> Cow<'_, str>;
// Provided method
fn unicode_truncate_aligned(
&self,
max_width: usize,
align: Alignment,
) -> (&str, usize) { ... }
}Expand description
Methods for padding or truncating using displayed width of Unicode strings.
Required Methods§
Sourcefn unicode_truncate(&self, max_width: usize) -> (&str, usize)
fn unicode_truncate(&self, max_width: usize) -> (&str, usize)
Truncates a string to be at most width in terms of display width by removing the end
characters.
For wide characters, it may not always be possible to truncate at exact width. In this case, the longest possible string is returned. To help the caller determine the situation, the display width of the returned string slice is also returned.
Zero-width characters decided by unicode_width are always included when deciding the
truncation point.
§Arguments
max_width- the maximum display width
Sourcefn unicode_truncate_start(&self, max_width: usize) -> (&str, usize)
fn unicode_truncate_start(&self, max_width: usize) -> (&str, usize)
Truncates a string to be at most width in terms of display width by removing the start
characters.
For wide characters, it may not always be possible to truncate at exact width. In this case, the longest possible string is returned. To help the caller determine the situation, the display width of the returned string slice is also returned.
Zero-width characters decided by unicode_width are always removed when deciding the
truncation point.
§Arguments
max_width- the maximum display width
Sourcefn unicode_truncate_centered(&self, max_width: usize) -> (&str, usize)
fn unicode_truncate_centered(&self, max_width: usize) -> (&str, usize)
Truncates a string to be at most width in terms of display width by removing
characters at both start and end.
For wide characters, it may not always be possible to truncate at exact width. In this case, the longest possible string is returned. To help the caller determine the situation, the display width of the returned string slice is also returned.
Zero-width characters decided by unicode_width are included if they are at end, or
removed if they are at the beginning when deciding the truncation point.
§Arguments
max_width- the maximum display width
Sourcefn unicode_pad(
&self,
target_width: usize,
align: Alignment,
truncate: bool,
) -> Cow<'_, str>
fn unicode_pad( &self, target_width: usize, align: Alignment, truncate: bool, ) -> Cow<'_, str>
Pads a string to be width in terms of display width. Only available when the std feature
of this library is activated, and it is activated by default.
When truncate is true, the string is truncated to width if necessary. In case of wide
characters and truncation point not at character boundary, the longest possible string is
used, and padded to exact width according to align.
See unicode_truncate for the behavior of
truncation.
§Arguments
target_width- the display width to pad toalign- alignment for truncation and paddingtruncate- whether to truncate string if necessary
Provided Methods§
Sourcefn unicode_truncate_aligned(
&self,
max_width: usize,
align: Alignment,
) -> (&str, usize)
fn unicode_truncate_aligned( &self, max_width: usize, align: Alignment, ) -> (&str, usize)
Truncates a string to be at most width in terms of display width by removing
characters.
Depending on the alignment characters are removed. When left aligned characters from the end are removed. When right aligned characters from the start are removed. When centered characters from both sides are removed.
For wide characters, it may not always be possible to truncate at exact width. In this case, the longest possible string is returned. To help the caller determine the situation, the display width of the returned string slice is also returned.
Zero-width characters decided by unicode_width are included if they are at end, or
removed if they are at the beginning when deciding the truncation point.
§Arguments
max_width- the maximum display widthalign- alignment for truncation