Skip to main content

HighlightedText

Struct HighlightedText 

Source
pub struct HighlightedText<S> { /* private fields */ }
Expand description

Represents text which was highlighted by the TextHighlighter.

Display implementations come in the form of Self::display_plain, Self::display_subs and Self::display_raw.

Implementations§

Source§

impl<S> HighlightedText<S>

Source

pub fn raw(&self) -> &S

Grab a handle to the raw data.

Source

pub fn raw_mut(&mut self) -> &mut S

Grab a mutable handle to the underlying data.

Source

pub fn markers(&self) -> [char; 2]

Source

pub fn map<T>(self, f: impl FnOnce(S) -> T) -> HighlightedText<T>

Swap the underlying string type, keeping the highlighter (e.g. line.map(str::to_owned)).

Source§

impl<S: AsRef<str>> HighlightedText<S>

Source

pub fn ranges(&self) -> impl Iterator<Item = Range<usize>> + '_

Source

pub fn pieces(&self) -> impl Iterator<Item = Piece<'_>> + '_

Walk the text as a stream of marker-free chunks: Piece::Text for unhighlighted runs and Piece::Match for each highlighted span.

Concatenating every chunk yields the same string as Self::display_plain, and the Piece::Match chunks are exactly the spans Self::ranges reports. Empty chunks are skipped.

Source

pub fn has_match(&self) -> bool

Whether any highlighted span is present.

Source

pub fn lines(&self) -> impl Iterator<Item = HighlightedText<&str>> + '_

Each line as its own highlighted text. A match never spans a newline, so every span stays within one line.

Source

pub fn to_plain(&self) -> Plain<'_>

The marker-free text together with the byte range of every match within that text – unlike Self::ranges, whose offsets index the raw, marker-bearing string.

Source

pub fn display_plain(&self) -> impl Display + '_

Display the highlighted text, stripping away the highlight markers.

Source

pub fn display_subs(&self, subs: [char; 2]) -> impl Display + '_

Display the highlighted text, replacing highlighted markers with subs.

Source

pub fn display_raw(&self) -> impl Display + '_

Display the highlighted text as-is, including markers.

Trait Implementations§

Source§

impl<S: AsRef<str>> AsRef<str> for HighlightedText<S>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: Clone> Clone for HighlightedText<S>

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<S: Copy> Copy for HighlightedText<S>

Source§

impl<S: AsRef<str>> Debug for HighlightedText<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for HighlightedText<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for HighlightedText<S>
where S: RefUnwindSafe,

§

impl<S> Send for HighlightedText<S>
where S: Send,

§

impl<S> Sync for HighlightedText<S>
where S: Sync,

§

impl<S> Unpin for HighlightedText<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for HighlightedText<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for HighlightedText<S>
where S: UnwindSafe,

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<S, T> Cast<T> for S
where T: Conv<S>,

Source§

fn cast(self) -> T

Cast from Self to T Read more
Source§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
Source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

Source§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
Source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
Source§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

Source§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
Source§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
Source§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
Source§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
Source§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
Source§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
Source§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
Source§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer 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<T> EscapeNonPrintablePosixExt for T
where T: AsRef<str>,

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> NormalizeDiacriticsExt for T
where T: AsRef<str> + ?Sized,

Source§

fn normalize_diacritics(&self) -> Cow<'_, str>

Normalize Latin diacritics to their ASCII equivalents (é -> e).
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> TruncateCharsExt for T
where T: AsRef<str> + ?Sized,

Source§

fn truncate_chars(&self, max_chars: usize) -> &str

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