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) -> Vec<usize>
pub fn span_boundaries(&self) -> Vec<usize>
Returns a sorted list of unique byte indices where styles change.
Sourcepub fn span_styles_hash(&self) -> u64
pub fn span_styles_hash(&self) -> u64
Computes a hash representing the contents of the span styles, suitable for cache invalidation.
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§fn clone(&self) -> AnnotatedString
fn clone(&self) -> AnnotatedString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more