pub struct AttributedString { /* private fields */ }Expand description
Text with optional style runs and links.
Implementations§
Source§impl AttributedString
impl AttributedString
Sourcepub fn new(
text: impl Into<String>,
runs: Vec<StyleRun>,
links: Vec<LinkRun>,
) -> Result<Self, AttributedError>
pub fn new( text: impl Into<String>, runs: Vec<StyleRun>, links: Vec<LinkRun>, ) -> Result<Self, AttributedError>
Create an attributed string from parts. Validates every range against the text (bounds + UTF-8 boundaries).
Sourcepub fn push_run(&mut self, run: StyleRun) -> Result<(), AttributedError>
pub fn push_run(&mut self, run: StyleRun) -> Result<(), AttributedError>
Append a style run, validating it against the current text.
Sourcepub fn push_link(&mut self, link: LinkRun) -> Result<(), AttributedError>
pub fn push_link(&mut self, link: LinkRun) -> Result<(), AttributedError>
Append a link, validating it against the current text.
Sourcepub fn validate(&self) -> Result<(), AttributedError>
pub fn validate(&self) -> Result<(), AttributedError>
Validate all ranges.
Sourcepub fn encode(&self) -> Result<Vec<u8>, AttributedError>
pub fn encode(&self) -> Result<Vec<u8>, AttributedError>
Encode the arena payload (without the outer [u32 byteLength] wrapper
the arena adds). The caller allocates the returned bytes in the arena or
the network string section.
Sourcepub fn encode_into(&self, out: &mut Vec<u8>) -> Result<(), AttributedError>
pub fn encode_into(&self, out: &mut Vec<u8>) -> Result<(), AttributedError>
Encode into an existing buffer.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, AttributedError>
pub fn decode(bytes: &[u8]) -> Result<Self, AttributedError>
Decode an arena payload (the bytes inside the arena’s length wrapper).
Sourcepub fn segments(&self) -> Vec<AttributedSegment<'_>>
pub fn segments(&self) -> Vec<AttributedSegment<'_>>
Split the text into non-overlapping segments, resolving overlapping runs in wire order (later wins per property; later link wins).
Trait Implementations§
Source§impl Clone for AttributedString
impl Clone for AttributedString
Source§impl Debug for AttributedString
impl Debug for AttributedString
Source§impl Default for AttributedString
impl Default for AttributedString
impl Eq for AttributedString
Source§impl From<&str> for AttributedString
impl From<&str> for AttributedString
Source§impl From<String> for AttributedString
impl From<String> for AttributedString
Source§impl PartialEq for AttributedString
impl PartialEq for AttributedString
impl StructuralPartialEq for AttributedString
Auto Trait Implementations§
impl Forget for AttributedString
impl Freeze for AttributedString
impl RefUnwindSafe for AttributedString
impl Send for AttributedString
impl Sync for AttributedString
impl Unpin for AttributedString
impl UnsafeUnpin for AttributedString
impl UnwindSafe for AttributedString
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
Mutably borrows from an owned value. Read more