Skip to main content

Text

Struct Text 

Source
pub struct Text { /* private fields */ }
Expand description

Styled text of any length: a paragraph, a table cell, a title.

Text from outside the program is safe to put here. Every character that is_unsafe refuses is removed, except newline and tab.

Every other line break becomes a newline: carriage return, vertical tab, form feed, next line, and the line and paragraph separators. A carriage return before a line feed is one break with it. A newline starts a new line. A tab expands to the next tab stop of the Context it is rendered in, counted from the start of its line.

Two texts are equal when their content, styles, and Overflow are. Empty pieces are dropped and neighbours in one style are joined, however the text was pushed.

Text is Renderable: Overflow decides how it fits a width.

Implementations§

Source§

impl Text

Source

pub fn new() -> Self

Text with nothing in it. It renders to no lines.

Source

pub fn plain(text: impl AsRef<str>) -> Self

text in the default style.

Source

pub fn styled(text: impl AsRef<str>, style: Style) -> Self

text in style.

Source

pub fn push(&mut self, text: impl AsRef<str>, style: Style)

Adds text in style after what is already there. A newline in text starts a new line.

Source

pub fn overflow(self, overflow: Overflow) -> Self

Sets what to do with a line wider than the width it renders at. The default is Overflow::KeepWords.

Source

pub fn lines(&self, tab_width: NonZeroU16) -> Vec<Line>

The text as lines, with tabs expanded to multiples of tab_width.

Nothing is wrapped. A text that ends in a newline ends in an empty line.

Source§

impl Text

Source

pub fn measure_as(&self, context: &Context, overflow: Overflow) -> Measurement

measure as if the text’s overflow were overflow, so a container that decides overflow per column measures a table cell without cloning it.

Source

pub fn render_as(&self, context: &Context, overflow: Overflow) -> Vec<Line>

render as if the text’s overflow were overflow, so a container that decides overflow per column renders a table cell without cloning it.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Text

Source§

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

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

impl Default for Text

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Text

Source§

impl From<&str> for Text

Source§

fn from(text: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Text

Source§

fn from(span: Span) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Text

Source§

fn from(text: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for Text

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Text

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Renderable for Text

Source§

fn measure(&self, context: &Context) -> Measurement

The narrowest and widest this content can usefully be.
Source§

fn render(&self, context: &Context) -> Vec<Line>

Lines no wider than context.width(), except a word or cluster that the content’s overflow policy keeps whole.
Source§

impl StructuralPartialEq for Text

Auto Trait Implementations§

§

impl Forget for Text

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin for Text

§

impl UnwindSafe for Text

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.