Skip to main content

ParsedText

Struct ParsedText 

Source
pub struct ParsedText {
    pub text: String,
    pub spans: Vec<Span>,
    pub links: Vec<Link>,
}
Expand description

The output of every parser in this crate.

Fields§

§text: String

The text to draw, with all markup removed.

§spans: Vec<Span>

Styled runs, sorted by start offset and non-overlapping. Runs with a wholly default style are omitted rather than materialised, so a plain message parses to zero spans.

§links: Vec<Link>

Link targets, indexed by LinkId.

Implementations§

Source§

impl ParsedText

Source

pub fn compact(&mut self)

Give back the spare capacity building left behind.

A parser pushes spans one at a time, so a line with two styled runs typically holds room for four; kept for the life of the scrollback, that slack is the largest single cost of a row. The buffer compacts every message it takes (see Message::compact).

By copying into an exact allocation rather than shrink_to_fit: shrinking in place splits every block into an odd-sized remainder, and a scrollback’s worth of those fragments the heap badly enough that appending runs three times slower and scrolling five. The copy frees whole blocks the allocator can hand straight back out.

Source

pub fn plain(text: impl Into<String>) -> ParsedText

A plain, unstyled string.

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn style_at(&self, at: usize) -> Style

The style in effect at byte offset at.

Linear over spans; callers walking the whole text in order should iterate spans directly instead. Present for hit-test and test assertions, which touch one offset at a time.

Mark range as a hyperlink, returning its id.

Used for autodetected URLs, which are found after parsing — markdown links come out of the parser already resolved. The difference matters: an autodetected URL can land anywhere, including straddling existing style runs, so this splits spans at the boundaries rather than assuming a clean fit.

Returns None for an empty or out-of-bounds range, or one that isn’t on char boundaries — a detector working in bytes shouldn’t be able to corrupt the span list.

The link covering byte at, if any.

Source

pub fn debug_assert_well_formed(&self)

Panics (in debug) unless the spans are sorted, non-empty, non-overlapping and inside the text. Called by the parsers’ tests; cheap enough to also call in debug builds of callers.

Trait Implementations§

Source§

impl Clone for ParsedText

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 ParsedText

Source§

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

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

impl Default for ParsedText

Source§

fn default() -> Self

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

impl Eq for ParsedText

Source§

impl PartialEq for ParsedText

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 ParsedText

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
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.