pub struct SpannedString<T> { /* private fields */ }
Expand description
A string with associated spans.
Each span has an associated attribute T
.
Implementations
sourceimpl SpannedString<Style>
impl SpannedString<Style>
sourcepub fn plain<S>(content: S) -> SpannedString<Style>where
S: Into<String>,
pub fn plain<S>(content: S) -> SpannedString<Style>where
S: Into<String>,
Returns a plain StyledString without any style.
You got no style, Dutch. You know that.
sourcepub fn styled<S, T>(content: S, style: T) -> SpannedString<Style>where
S: Into<String>,
T: Into<Style>,
pub fn styled<S, T>(content: S, style: T) -> SpannedString<Style>where
S: Into<String>,
T: Into<Style>,
Creates a new StyledString
using a single style for the entire text.
sourcepub fn append_plain<S>(&mut self, text: S)where
S: Into<String>,
pub fn append_plain<S>(&mut self, text: S)where
S: Into<String>,
Appends the given plain text to self
.
sourceimpl SpannedString<()>
impl SpannedString<()>
sourceimpl<T> SpannedString<T>
impl<T> SpannedString<T>
sourcepub fn new() -> SpannedString<T>
pub fn new() -> SpannedString<T>
Returns an empty SpannedString
.
sourcepub fn with_spans<S>(
source: S,
spans: Vec<IndexedSpan<T>, Global>
) -> SpannedString<T>where
S: Into<String>,
pub fn with_spans<S>(
source: S,
spans: Vec<IndexedSpan<T>, Global>
) -> SpannedString<T>where
S: Into<String>,
Creates a new SpannedString
manually.
It is not recommended to use this directly.
Instead, look for methods like Markdown::parse
.
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) -> SpannedString<T>where
S: Into<String>,
pub fn single_span<S>(source: S, attr: T) -> SpannedString<T>where
S: Into<String>,
Returns a new SpannedString with a single span.
sourcepub fn append<S>(&mut self, other: S)where
S: Into<SpannedString<T>>,
pub fn append<S>(&mut self, other: S)where
S: Into<SpannedString<T>>,
Appends the given StyledString
to self
.
sourcepub fn append_raw(&mut self, source: &str, spans: Vec<IndexedSpan<T>, Global>)
pub fn append_raw(&mut self, source: &str, spans: Vec<IndexedSpan<T>, Global>)
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 + ExactSizeIterator
pub fn spans(&self) -> impl DoubleEndedIterator + ExactSizeIterator
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 + ExactSizeIterator
pub fn spans_raw_attr_mut(
&mut self
) -> impl DoubleEndedIterator + ExactSizeIterator
Returns a mutable iterator on the spans of this string.
This can be used to modify the style of each span.
Trait Implementations
sourceimpl<T> Clone for SpannedString<T>where
T: Clone,
impl<T> Clone for SpannedString<T>where
T: Clone,
sourcefn clone(&self) -> SpannedString<T>
fn clone(&self) -> SpannedString<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T> Debug for SpannedString<T>where
T: Debug,
impl<T> Debug for SpannedString<T>where
T: Debug,
sourceimpl<T> Default for SpannedString<T>
impl<T> Default for SpannedString<T>
sourcefn default() -> SpannedString<T>
fn default() -> SpannedString<T>
Returns the “default value” for a type. Read more
sourceimpl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T>
impl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T>
sourcefn from(other: &'a SpannedString<T>) -> SpannedStr<'a, T>
fn from(other: &'a SpannedString<T>) -> SpannedStr<'a, T>
Converts to this type from the input type.
sourceimpl<S, T> From<S> for SpannedString<T>where
S: Into<String>,
T: Default,
impl<S, T> From<S> for SpannedString<T>where
S: Into<String>,
T: Default,
sourcefn from(value: S) -> SpannedString<T>
fn from(value: S) -> SpannedString<T>
Converts to this type from the input type.
sourceimpl<T> FromIterator<SpannedString<T>> for SpannedString<T>
impl<T> FromIterator<SpannedString<T>> for SpannedString<T>
sourcefn from_iter<I>(iter: I) -> SpannedString<T>where
I: IntoIterator<Item = SpannedString<T>>,
fn from_iter<I>(iter: I) -> SpannedString<T>where
I: IntoIterator<Item = SpannedString<T>>,
Creates a value from an iterator. Read more
sourceimpl<T> Hash for SpannedString<T>where
T: Hash,
impl<T> Hash for SpannedString<T>where
T: Hash,
sourceimpl<T> PartialEq<SpannedString<T>> for SpannedString<T>where
T: PartialEq<T>,
impl<T> PartialEq<SpannedString<T>> for SpannedString<T>where
T: PartialEq<T>,
sourcefn eq(&self, other: &SpannedString<T>) -> bool
fn eq(&self, other: &SpannedString<T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl<'a, T> SpannedText for &'a SpannedString<T>
impl<'a, T> SpannedText for &'a SpannedString<T>
type S = IndexedSpan<T>
type S = IndexedSpan<T>
Type of span returned by SpannedText::spans()
.
sourcefn spans(&self) -> &[IndexedSpan<T>]
fn spans(&self) -> &[IndexedSpan<T>]
Returns the spans for this text.
sourcefn as_ref(&self) -> SpannedTextRef<'_, Self>
fn as_ref(&self) -> SpannedTextRef<'_, Self>
Returns a SpannedText
by reference.
impl<T> Eq for SpannedString<T>where
T: Eq,
impl<T> StructuralEq for SpannedString<T>
impl<T> StructuralPartialEq for SpannedString<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more