Struct cursive_core::utils::span::SpannedString
source · 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) -> Selfwhere
S: Into<String>,
pub fn plain<S>(content: S) -> Selfwhere
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) -> Selfwhere
S: Into<String>,
T: Into<Style>,
pub fn styled<S, T>(content: S, style: T) -> Selfwhere
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
.
source§impl SpannedString<()>
impl SpannedString<()>
source§impl<T> SpannedString<T>
impl<T> SpannedString<T>
sourcepub fn with_spans<S>(source: S, spans: Vec<IndexedSpan<T>>) -> Selfwhere
S: Into<String>,
pub fn with_spans<S>(source: S, spans: Vec<IndexedSpan<T>>) -> Selfwhere
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) -> Selfwhere
S: Into<String>,
pub fn single_span<S>(source: S, attr: T) -> Selfwhere
S: Into<String>,
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.
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<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<SpannedString<T>> for SpannedString<T>
impl<T: PartialEq> PartialEq<SpannedString<T>> for SpannedString<T>
source§fn eq(&self, other: &SpannedString<T>) -> bool
fn eq(&self, other: &SpannedString<T>) -> bool
source§impl<'a, T> SpannedText for &'a SpannedString<T>
impl<'a, T> SpannedText for &'a SpannedString<T>
§type S = IndexedSpan<T>
type S = IndexedSpan<T>
SpannedText::spans()
.source§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.