Skip to main content

Grapheme

Struct Grapheme 

Source
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

Source

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.

Source

pub fn as_str(&self) -> &str

Source

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.

Trait Implementations§

Source§

impl Debug for Grapheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Grapheme

Source§

fn eq(&self, other: &Grapheme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Grapheme

Source§

impl StructuralPartialEq for Grapheme

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more