Skip to main content

CellWidth

Trait CellWidth 

Source
pub trait CellWidth {
    // Required method
    fn cell_width(&self) -> u16;
}
Expand description

Returns the display width of a value in terminal cells.

This trait provides a unified way to compute cell widths for both string content and Cells:

  • str: width is derived from UnicodeWidthStr, with a fast path for single-byte ASCII characters and a terminal-compatibility adjustment for halfwidth katakana dakuten/handakuten (U+FF9E/U+FF9F).
  • Cell: returns the CellDiffOption::ForcedWidth when set, otherwise falls back to the width of the cell’s symbol.

Required Methods§

Source

fn cell_width(&self) -> u16

Returns the display width in terminal cells.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CellWidth for str

Source§

fn cell_width(&self) -> u16

Returns the display width in terminal cells.

§Note

Control characters are filtered out by Span::styled_graphemes() and Buffer::set_stringn() before reaching this point. Cell::set_symbol() and set_char() do not filter, but those are low-level APIs where the caller is responsible for providing valid content. Single-byte control characters that slip through will be reported as width 1.

Implementors§