Skip to main content

Span

Struct Span 

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

A run of text in one style, on one line.

A span holds no character that is_unsafe refuses, so no escape sequence, directional override, or line separator reaches a terminal through it. It holds no tab either. A cluster never spans two spans, so a line’s width is the sum of its spans’ widths.

Its Display prints the text without the style.

Implementations§

Source§

impl Span

Source

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

A span of text in style.

Tabs expand to the next multiple of TAB_WIDTH cells, counted from the start of the span. That is right for a span that starts its line.

A span is one line, so every line break becomes a space, and the words around it stay apart. The line breaks are newline, carriage return, vertical tab, form feed, next line, and the line and paragraph separators. Every other unsafe character is removed.

Build text that spans lines, or follows other spans on a line, with Text. It splits at each newline and counts tab stops from the line start.

To keep an owned String as the span’s text when it needs no change, use Span::from(string).

Source

pub fn text(&self) -> &str

The text, without escape sequences, tabs, or line breaks.

Source

pub fn style(&self) -> Style

The style the text is drawn in. Layout never changes it.

Source

pub fn width(&self) -> u16

The width of the text in terminal cells.

Trait Implementations§

Source§

impl Clone for Span

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 Span

Source§

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

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

impl Display for Span

Source§

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

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

impl Eq for Span

Source§

impl Extend<Span> for Line

Source§

fn extend<I: IntoIterator<Item = Span>>(&mut self, spans: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<&str> for Span

Source§

fn from(text: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Line

Source§

fn from(span: Span) -> 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 Span

Source§

fn from(text: String) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Span> for Line

Source§

fn from_iter<I: IntoIterator<Item = Span>>(spans: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Span

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 Span

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 StructuralPartialEq for Span

Auto Trait Implementations§

§

impl Forget for Span

§

impl Freeze for Span

§

impl Move for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnsafeUnpin for Span

§

impl UnwindSafe for Span

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.