[][src]Trait unicode_truncate::UnicodeTruncateStr

pub trait UnicodeTruncateStr {
    pub fn unicode_truncate(&self, width: usize) -> (&str, usize);
pub fn unicode_truncate_start(&self, width: usize) -> (&str, usize);
pub fn unicode_pad(
        &self,
        width: usize,
        align: Alignment,
        truncate: bool
    ) -> Cow<'_, str>; }

Methods for padding or truncating using displayed width of Unicode strings.

Required methods

pub fn unicode_truncate(&self, width: usize) -> (&str, usize)[src]

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

  • width - the maximum display width

pub fn unicode_truncate_start(&self, width: usize) -> (&str, usize)[src]

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 included when deciding the truncation point.

Arguments

  • width - the maximum display width

pub fn unicode_pad(
    &self,
    width: usize,
    align: Alignment,
    truncate: bool
) -> Cow<'_, str>
[src]

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

  • width - the display width to pad to
  • align - alignment for padding
  • truncate - whether to truncate string if necessary
Loading content...

Implementations on Foreign Types

impl UnicodeTruncateStr for str[src]

Loading content...

Implementors

Loading content...