pub struct SpannedString<T> { /* private fields */ }
Expand description
A string with associated spans.
Each span has an associated attribute T
.
Implementations§
Source§impl SpannedString<Style>
impl SpannedString<Style>
Sourcepub fn plain<S>(content: S) -> Self
pub fn plain<S>(content: S) -> Self
Returns a plain StyledString without any style.
You got no style, Dutch. You know that.
Sourcepub fn styled<S, T>(content: S, style: T) -> Self
pub fn styled<S, T>(content: S, style: T) -> Self
Creates a new StyledString
using a single style for the entire text.
Sourcepub fn append_plain<S>(&mut self, text: S)
pub fn append_plain<S>(&mut self, text: S)
Appends the given plain text to self
.
Source§impl SpannedString<()>
impl SpannedString<()>
Source§impl<T> SpannedString<T>
impl<T> SpannedString<T>
Sourcepub fn concatenate<I>(spans: I) -> Selfwhere
I: IntoIterator<Item = Self>,
pub fn concatenate<I>(spans: I) -> Selfwhere
I: IntoIterator<Item = Self>,
Concatenates all styled strings.
Same as spans.into_iter().collect()
.
Sourcepub fn with_spans<S>(source: S, spans: Vec<IndexedSpan<T>>) -> Self
pub fn with_spans<S>(source: S, spans: Vec<IndexedSpan<T>>) -> Self
Creates a new SpannedString
manually.
It is not recommended to use this directly.
Instead, look for methods like Markdown::parse
.
Sourcepub fn canonicalize(&mut self)where
T: PartialEq,
pub fn canonicalize(&mut self)where
T: PartialEq,
Compacts and simplifies this string, resulting in a canonical form.
If two styled strings represent the same styled text, they should have equal canonical forms.
(The PartialEq implementation for StyledStrings requires both the source and spans to be equals, so non-visible changes such as text in the source between spans could cause StyledStrings to evaluate as non-equal.)
Sourcepub fn canonical(self) -> Selfwhere
T: PartialEq,
pub fn canonical(self) -> Selfwhere
T: PartialEq,
Returns the canonical form of this styled string.
Sourcepub fn compact(&mut self)
pub fn compact(&mut self)
Compacts the source to only include the spans content.
This does not change the number of spans, but changes the source.
Sourcepub fn simplify(&mut self)where
T: PartialEq,
pub fn simplify(&mut self)where
T: PartialEq,
Attemps to reduce the number of spans by merging consecutive similar ones.
Sourcepub fn trim_start(&mut self)
pub fn trim_start(&mut self)
Shrink the source to discard any unused prefix.
Sourcepub fn single_span<S>(source: S, attr: T) -> Self
pub fn single_span<S>(source: S, attr: T) -> Self
Returns a new SpannedString with a single span.
Sourcepub fn append<S>(&mut self, other: S)where
S: Into<Self>,
pub fn append<S>(&mut self, other: S)where
S: Into<Self>,
Appends the given StyledString
to self
.
Sourcepub fn append_raw(&mut self, source: &str, spans: Vec<IndexedSpan<T>>)
pub fn append_raw(&mut self, source: &str, spans: Vec<IndexedSpan<T>>)
Appends content
and its corresponding spans to the end.
It is not recommended to use this directly;
instead, look at the append
method.
Sourcepub fn remove_spans<R>(&mut self, range: R)where
R: RangeBounds<usize>,
pub fn remove_spans<R>(&mut self, range: R)where
R: RangeBounds<usize>,
Remove the given range of spans from the styled string.
You may want to follow this with either compact()
,
trim_start()
or trim_end()
.
Sourcepub fn spans(
&self,
) -> impl DoubleEndedIterator<Item = Span<'_, T>> + ExactSizeIterator<Item = Span<'_, T>>
pub fn spans( &self, ) -> impl DoubleEndedIterator<Item = Span<'_, T>> + ExactSizeIterator<Item = Span<'_, T>>
Iterates on the resolved spans.
Sourcepub fn spans_attr_mut(&mut self) -> impl Iterator<Item = SpanMut<'_, T>>
pub fn spans_attr_mut(&mut self) -> impl Iterator<Item = SpanMut<'_, T>>
Iterates on the resolved spans, with mutable access to the attributes.
Sourcepub fn spans_raw(&self) -> &[IndexedSpan<T>]
pub fn spans_raw(&self) -> &[IndexedSpan<T>]
Returns a reference to the indexed spans.
Sourcepub fn spans_raw_attr_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = IndexedSpanRefMut<'_, T>> + ExactSizeIterator<Item = IndexedSpanRefMut<'_, T>>
pub fn spans_raw_attr_mut( &mut self, ) -> impl DoubleEndedIterator<Item = IndexedSpanRefMut<'_, T>> + ExactSizeIterator<Item = IndexedSpanRefMut<'_, T>>
Returns a mutable iterator on the spans of this string.
This can be used to modify the style of each span.
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
Returns a reference to the source string.
This is the non-parsed string.
Sourcepub fn into_source(self) -> String
pub fn into_source(self) -> String
Get the source, consuming this StyledString
.
Trait Implementations§
Source§impl<T: Clone> Clone for SpannedString<T>
impl<T: Clone> Clone for SpannedString<T>
Source§fn clone(&self) -> SpannedString<T>
fn clone(&self) -> SpannedString<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for SpannedString<T>
impl<T: Debug> Debug for SpannedString<T>
Source§impl<T> Default for SpannedString<T>
impl<T> Default for SpannedString<T>
Source§impl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T>
impl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T>
Source§fn from(other: &'a SpannedString<T>) -> Self
fn from(other: &'a SpannedString<T>) -> Self
Source§impl<S, T> From<S> for SpannedString<T>
impl<S, T> From<S> for SpannedString<T>
Source§impl<T> FromIterator<SpannedString<T>> for SpannedString<T>
impl<T> FromIterator<SpannedString<T>> for SpannedString<T>
Source§fn from_iter<I: IntoIterator<Item = SpannedString<T>>>(
iter: I,
) -> SpannedString<T>
fn from_iter<I: IntoIterator<Item = SpannedString<T>>>( iter: I, ) -> SpannedString<T>
Source§impl<T: Hash> Hash for SpannedString<T>
impl<T: Hash> Hash for SpannedString<T>
Source§impl<T: PartialEq> PartialEq for SpannedString<T>
impl<T: PartialEq> PartialEq for SpannedString<T>
Source§impl<'a, T> SpannedText for &'a SpannedString<T>
impl<'a, T> SpannedText for &'a SpannedString<T>
Source§type S = IndexedSpan<T>
type S = IndexedSpan<T>
SpannedText::spans()
. Read moreSource§fn spans(&self) -> &[IndexedSpan<T>]
fn spans(&self) -> &[IndexedSpan<T>]
Source§fn as_ref(&self) -> SpannedTextRef<'_, Self>
fn as_ref(&self) -> SpannedTextRef<'_, Self>
SpannedText
by reference.impl<T: Eq> Eq for SpannedString<T>
impl<T> StructuralPartialEq for SpannedString<T>
Auto Trait Implementations§
impl<T> Freeze for SpannedString<T>
impl<T> RefUnwindSafe for SpannedString<T>where
T: RefUnwindSafe,
impl<T> Send for SpannedString<T>where
T: Send,
impl<T> Sync for SpannedString<T>where
T: Sync,
impl<T> Unpin for SpannedString<T>where
T: Unpin,
impl<T> UnwindSafe for SpannedString<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.