pub struct RichTextBuilder { /* private fields */ }
Expand description
A builder for creating RichText
objects.
This builder allows you to construct a RichText
object by building up a sequence
of styled sub-strings; first you push
a &str
onto the string,
and then you can optionally add styles to that text via the returned AttributesAdder
object.
Example
let mut builder = RichTextBuilder::new();
builder.push("Hello ");
builder.push("World!").weight(FontWeight::BOLD);
// Can also use write!
write!(builder, "Here is your number: {}", 1).underline(true).text_color(Color::RED);
let rich_text = builder.build();
Implementations§
§impl RichTextBuilder
impl RichTextBuilder
pub fn new() -> RichTextBuilder
pub fn new() -> RichTextBuilder
Create a new RichTextBuilder
.
pub fn push(&mut self, string: &str) -> AttributesAdder<'_>
pub fn push(&mut self, string: &str) -> AttributesAdder<'_>
Append a &str
to the end of the text.
This method returns a AttributesAdder
that can be used to style the newly
added string slice.
pub fn add_attributes_for_range(
&mut self,
range: impl RangeBounds<usize>
) -> AttributesAdder<'_>
pub fn add_attributes_for_range( &mut self, range: impl RangeBounds<usize> ) -> AttributesAdder<'_>
Get an AttributesAdder
for the given range.
This can be used to modify styles for a given range after it has been added.
Trait Implementations§
§impl Default for RichTextBuilder
impl Default for RichTextBuilder
§fn default() -> RichTextBuilder
fn default() -> RichTextBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for RichTextBuilder
impl !Send for RichTextBuilder
impl !Sync for RichTextBuilder
impl Unpin for RichTextBuilder
impl !UnwindSafe for RichTextBuilder
Blanket Implementations§
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
§fn round_from(x: T) -> T
fn round_from(x: T) -> T
Performs the conversion.
§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,
§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.