Skip to main content

PrintableText

Struct PrintableText 

Source
pub struct PrintableText(/* private fields */);
Expand description

One line of plain text: a row of cells, every character printable.

This is the unit measurement is defined on — it holds no control characters at all, not even \n. PrintableLines spans rows and therefore has no width; a PrintableText is exactly one row, so its cells come to a single number.

Implementations§

Source§

impl PrintableText

Source

pub fn new(text: &str) -> &Self

Adopts one line of plain text.

§Panics

In debug builds, panics when text holds any control character, \n included — a line is one row of cells, so a line break inside it is as much a contract violation as an escape sequence. Release builds do not check.

Source

pub fn as_str(&self) -> &str

Source

pub fn width(&self) -> usize

Returns the terminal cells this line occupies.

This is the crate’s one definition of display width: CJK ideographs take two cells, an emoji ZWJ sequence takes two, and a combining mark takes none. Because the receiver is a single line and cannot hold escapes or cursor movement, nothing has to be scanned for or skipped.

The cell rules are defined in one place inside the crate, which is where a measure that depended on the terminal — ambiguous East Asian width resolved as one cell or two — would take its input.

Source

pub fn truncate(&self, width: usize) -> &Self

Cuts to at most width cells, on a grapheme boundary.

A grapheme that would straddle the limit is dropped rather than split, so the result never exceeds width and never leaves half a wide character behind.

Source

pub fn graphemes(&self) -> impl Iterator<Item = &Grapheme>

Splits into grapheme clusters, the unit a cell boundary may fall on.

Trait Implementations§

Source§

impl Debug for PrintableText

Source§

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

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

impl PartialEq for PrintableText

Source§

fn eq(&self, other: &PrintableText) -> 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 PrintableText

Source§

impl StructuralPartialEq for PrintableText

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