pub struct StyledStringBuilder { /* private fields */ }Expand description
Builder for StyledStrings.
A builder can be initialized from scratch via StyledString::builder() or Default.
Alternatively, it can be initialized from an existing StyledString.
A builder can be extended by pushing text, styles
or StyledStrings into it.
§Examples
let mut builder = StyledString::builder();
builder.push_style(AnsiColor::BrightGreen.on(AnsiColor::White).bold());
builder.push_text("Hello");
builder.push_text(",");
// It's possible to use `+=` as syntactic sugar for `push_str()` / `push_style()`.
builder += Style::new();
builder.push_text(" world");
builder += styled!("[[it, dim]]!");
let s = builder.build();
assert_eq!(
s.to_string(),
"[[bold green! on white]]Hello,[[/]] world[[italic dim]]!"
);Implementations§
Source§impl StyledStringBuilder
impl StyledStringBuilder
Sourcepub fn push_text(&mut self, text: &str)
pub fn push_text(&mut self, text: &str)
Pushes unstyled text at the end of the string.
§Panics
Panics if text contains an ANSI escape char (\x1b).
Sourcepub fn push_style(&mut self, style: Style)
pub fn push_style(&mut self, style: Style)
Pushes a style at the end of this string.
Sourcepub fn build(self) -> StyledString
pub fn build(self) -> StyledString
Finalizes the StyledString.
Trait Implementations§
Source§impl AddAssign<Style> for StyledStringBuilder
impl AddAssign<Style> for StyledStringBuilder
Source§fn add_assign(&mut self, rhs: Style)
fn add_assign(&mut self, rhs: Style)
Performs the
+= operation. Read moreSource§impl AddAssign<StyledStr<'_>> for StyledStringBuilder
impl AddAssign<StyledStr<'_>> for StyledStringBuilder
Source§fn add_assign(&mut self, rhs: StyledStr<'_>)
fn add_assign(&mut self, rhs: StyledStr<'_>)
Performs the
+= operation. Read moreSource§impl Clone for StyledStringBuilder
impl Clone for StyledStringBuilder
Source§fn clone(&self) -> StyledStringBuilder
fn clone(&self) -> StyledStringBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StyledStringBuilder
impl Debug for StyledStringBuilder
Source§impl Default for StyledStringBuilder
impl Default for StyledStringBuilder
Source§fn default() -> StyledStringBuilder
fn default() -> StyledStringBuilder
Returns the “default value” for a type. Read more
Source§impl From<StyledString> for StyledStringBuilder
impl From<StyledString> for StyledStringBuilder
Source§fn from(string: StyledString) -> Self
fn from(string: StyledString) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for StyledStringBuilder
impl RefUnwindSafe for StyledStringBuilder
impl Send for StyledStringBuilder
impl Sync for StyledStringBuilder
impl Unpin for StyledStringBuilder
impl UnwindSafe for StyledStringBuilder
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