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) -> AnnotatedString
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 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_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.
pub fn render_hash(&self) -> u64
Sourcepub fn subsequence(&self, range: Range<usize>) -> AnnotatedString
pub fn subsequence(&self, range: Range<usize>) -> AnnotatedString
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnnotatedString
impl Debug for AnnotatedString
Source§impl Default for AnnotatedString
impl Default for AnnotatedString
Source§fn default() -> AnnotatedString
fn default() -> AnnotatedString
Source§impl From<&String> for AnnotatedString
impl From<&String> for AnnotatedString
Source§fn from(text: &String) -> AnnotatedString
fn from(text: &String) -> AnnotatedString
Source§impl From<&mut String> for AnnotatedString
impl From<&mut String> for AnnotatedString
Source§fn from(text: &mut String) -> AnnotatedString
fn from(text: &mut String) -> AnnotatedString
Source§impl From<&str> for AnnotatedString
impl From<&str> for AnnotatedString
Source§fn from(text: &str) -> AnnotatedString
fn from(text: &str) -> AnnotatedString
Source§impl From<String> for AnnotatedString
impl From<String> for AnnotatedString
Source§fn from(text: String) -> AnnotatedString
fn from(text: String) -> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.