pub struct Grapheme(/* private fields */);Expand description
One grapheme cluster: the smallest run of text a cell boundary may fall on.
PrintableText is one row and PrintableLines spans rows, but neither
says how far a single cell reaches. A cluster does, and that is the unit the
layout pass turns into a token: a
StyledGrapheme holds one of these and the cells
it occupies, so a renderer that cannot split a cluster is a renderer that
cannot disagree about a width.
The distinction is not decorative. A row of tokens whose widths sum to the rectangle’s width still renders wrong if one token holds three clusters, because a backend writes a token into the single cell its width starts at.
Implementations§
Source§impl Grapheme
impl Grapheme
Sourcepub fn new(text: &str) -> &Self
pub fn new(text: &str) -> &Self
Adopts one grapheme cluster.
§Panics
In debug builds, panics when text is not exactly one printable
grapheme cluster — empty text, several clusters, or a control
character. Release builds do not check.
pub fn as_str(&self) -> &str
Sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
Returns the terminal cells this cluster occupies.
Defined by the crate’s shared width implementation, exactly
as PrintableText::width is.