pub struct AnnotatedString {
pub text: String,
pub span_styles: Vec<RangeStyle<SpanStyle>>,
pub paragraph_styles: Vec<RangeStyle<ParagraphStyle>>,
pub string_annotations: Vec<RangeStyle<StringAnnotation>>,
pub link_annotations: Vec<RangeStyle<LinkAnnotation>>,
}Expand description
The basic data structure of text with multiple styles.
To construct an AnnotatedString you can use AnnotatedString::builder().
Fields§
§text: String§span_styles: Vec<RangeStyle<SpanStyle>>§paragraph_styles: Vec<RangeStyle<ParagraphStyle>>§string_annotations: Vec<RangeStyle<StringAnnotation>>Arbitrary tag+value annotations. Used for e.g. clickable link URLs.
Mirrors JC AnnotatedString.getStringAnnotations(tag, start, end).
link_annotations: Vec<RangeStyle<LinkAnnotation>>Link annotations — URLs and clickable actions.
Mirrors JC AnnotatedString.getLinkAnnotations(start, end).
Implementations§
Source§impl AnnotatedString
impl AnnotatedString
pub fn new(text: String) -> Self
pub fn builder() -> Builder
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn span_boundaries(&self) -> SpanBoundaries
pub fn span_boundaries(&self) -> SpanBoundaries
Returns a sorted list of unique byte indices where styles change.
Sourcepub fn render_string(&self) -> RenderString
pub fn render_string(&self) -> RenderString
Returns the RenderString view of this string: everything rendering
reads (content, styles, link identity), nothing it must not touch
(link handlers). A clone-conversion — memoize at the call site when
the same AnnotatedString lowers every frame.
Sourcepub fn span_measurement_hash(&self) -> u64
pub fn span_measurement_hash(&self) -> u64
Hash of the span styles’ ranges and the attributes that change how the text measures: two strings with the same text and hash measure alike, whatever their spans’ colors, backgrounds or decorations.
pub fn render_hash(&self) -> u64
Sourcepub fn subsequence(&self, range: Range<usize>) -> Self
pub fn subsequence(&self, range: Range<usize>) -> Self
Returns a new AnnotatedString containing a substring of the original text
and any styles that overlap with the new range, with indices adjusted.
Sourcepub fn get_string_annotations(
&self,
tag: &str,
start: usize,
end: usize,
) -> Vec<&RangeStyle<StringAnnotation>>
pub fn get_string_annotations( &self, tag: &str, start: usize, end: usize, ) -> Vec<&RangeStyle<StringAnnotation>>
Returns all string annotations with the given tag whose range overlaps [start, end).
JC parity: AnnotatedString.getStringAnnotations(tag, start, end) -> List<Range<String>>
Sourcepub fn get_link_annotations(
&self,
start: usize,
end: usize,
) -> Vec<&RangeStyle<LinkAnnotation>>
pub fn get_link_annotations( &self, start: usize, end: usize, ) -> Vec<&RangeStyle<LinkAnnotation>>
Returns all link annotations whose range overlaps [start, end).
JC parity: AnnotatedString.getLinkAnnotations(start, end)
Trait Implementations§
Source§impl Clone for AnnotatedString
impl Clone for AnnotatedString
Source§impl Debug for AnnotatedString
impl Debug for AnnotatedString
Source§impl Default for AnnotatedString
impl Default for AnnotatedString
Source§impl From<&String> for AnnotatedString
impl From<&String> for AnnotatedString
Source§impl From<&mut String> for AnnotatedString
impl From<&mut String> for AnnotatedString
Source§impl From<&str> for AnnotatedString
impl From<&str> for AnnotatedString
Source§impl From<String> for AnnotatedString
impl From<String> for AnnotatedString
Source§impl PartialEq for AnnotatedString
impl PartialEq for AnnotatedString
impl StructuralPartialEq for AnnotatedString
Auto Trait Implementations§
impl !RefUnwindSafe for AnnotatedString
impl !Send for AnnotatedString
impl !Sync for AnnotatedString
impl !UnwindSafe for AnnotatedString
impl Freeze for AnnotatedString
impl Unpin for AnnotatedString
impl UnsafeUnpin for AnnotatedString
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,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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