Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

A builder to construct AnnotatedString.

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Source

pub fn append(self, text: &str) -> Self

Appends the given String to this Builder.

Source

pub fn append_annotated(self, annotated: &AnnotatedString) -> Self

Source

pub fn append_annotated_subsequence( self, annotated: &AnnotatedString, range: Range<usize>, ) -> Self

Source

pub fn push_style(self, style: SpanStyle) -> Self

Applies the given SpanStyle to any appended text until a corresponding pop is called.

Returns the index of the pushed style, which can be passed to pop_to or used as an ID.

Source

pub fn push_paragraph_style(self, style: ParagraphStyle) -> Self

Applies the given ParagraphStyle to any appended text until a corresponding pop is called.

Source

pub fn push_string_annotation(self, tag: &str, annotation: &str) -> Self

Pushes a string annotation covering subsequent appended text until the matching pop.

JC parity: Builder.pushStringAnnotation(tag, annotation)

Pushes a LinkAnnotation covering subsequent appended text. Call [pop] when done, or use [with_link] for the block form.

JC parity: Builder.pushLink(link)

Block form of [push_link] — mirrors JC’s withLink(link) { ... } DSL.

§Example
builder
    .append("Visit ")
    .with_link(
        LinkAnnotation::Url("https://developer.android.com".into()),
        |b| b.append("Android Developers"),
    )
    .append(".")
    .to_annotated_string()
Source

pub fn pop(self) -> Self

Ends the style that was most recently pushed.

Source

pub fn to_annotated_string(self) -> AnnotatedString

Completes the builder, resolving open styles to the end of the text.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.