Skip to main content

RenderedText

Struct RenderedText 

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

A snapshot of the text a TextViewState renders, as of one parse of its content.

Offsets into it are UTF-8 byte offsets. It is the string plain copy produces: hello **world** renders as hello world, escapes are resolved, and heading markers and list markers are left out. Blocks end with a newline and table cells are joined with a space; those separators belong to no block, so no highlight paints them.

Two snapshots are equal when they come from the same view and the same parse. Comparing the current rendered_text with the one last searched tells an observer of the view whether its content changed, so setting highlights, which notifies the view too, does not start another search. The text itself is only built when it is first read, from the parsed document the snapshot holds on to, so drop a snapshot that is no longer needed rather than keeping it past many changes.

Implementations§

Source§

impl RenderedText

Source

pub fn as_str(&self) -> &str

The rendered text.

Source

pub fn len(&self) -> usize

The length of the rendered text, in bytes.

Source

pub fn is_empty(&self) -> bool

Whether the view renders no text.

Source

pub fn source(&self) -> &str

The source this text was rendered from, whose byte ranges range_for_source takes.

It comes from the same parse as the text, so it trails the text last given to the view until that text’s parse lands. Before converting a range, check that it indexes this source: while text is streamed in, this source is a prefix of the text the application holds, and after set_text it may be different text.

Source

pub fn range_for_source(&self, source: Range<usize>) -> Option<Range<usize>>

The range of this text rendered from source, a UTF-8 byte range of Self::source.

This converts a range of the Markdown source, such as one selected_source_range returned or one an application stored with its own data, into the range a RangeHighlight takes. A character is rendered from source when any of the source it was rendered from lies in it: all of &amp; for &, the \ and the * of \*, the whole source of an inline object for its text. Source that renders nothing, such as emphasis delimiters, heading and list markers, code fences, table pipes and link destinations, adds nothing, so **bold** and bold give the same range.

The result is the smallest range holding every character rendered from source. When source spans blocks, it also holds the separators between them, which a highlight leaves unpainted. Text the parser recorded no source position for, such as the text of inline HTML, is only included when it lies between characters that are.

Converting the source range a selection of this text reports gives the selected range back, widened only to whole characters where several share their source, like the text of an inline object. The separators between blocks are rendered from no source, so one at either end of the selection is left out: Select All gives back everything but the line break after the last block.

Returns None when source is empty, reversed, out of bounds, or not on a character boundary, or when nothing is rendered from it. HTML views record no source positions, so they always return None.

Trait Implementations§

Source§

impl Clone for RenderedText

Source§

fn clone(&self) -> RenderedText

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 RenderedText

Source§

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

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

impl Eq for RenderedText

Source§

impl PartialEq for RenderedText

Source§

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

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

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

Inequality operator !=. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more