pub struct StyledStrings { /* private fields */ }
Expand description

StyledStrings is vector of StyledString and almost the same as Vec<String>. It is possible to change the color and attribute of each String. That’s why, if you don’t change any color or attribute, you should use ‘StyledString’ not StyledStrings

Example

let mut texts = StyledStrings::default();
texts.push_str("Default color is gray, ");
texts.push_str_with_color("and it is possible to color text.\n", Color::Red);
texts.push_str("Basically, this `StyledStrings` is one sentence, ");
texts.push_str_with_color("so if you want to multiline sentences, you need to add `\n`.", Color::Magenta);
println!("{}", texts); // Pushed colored text are displayed

Basically,initialize by default with mutable. Then, &str(s) are pushed to the Vec, specifying colors or attributes.

Implementations§

source§

impl StyledStrings

source

pub fn push_str(&mut self, s: &str)

It is possible push &str type with gray color to Vector.

Example
let mut texts = StyledStrings::default();
texts.push_str("sample text");
texts.push_str("\n");
texts.push_str("new text here");
println!("{}", texts);
 /*
    sample text
    new text here
 */
source

pub fn push_str_with_color<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color
)

It is possible to push &str type with specify color to Vector.

Example
let mut texts = StyledStrings::default();
texts.push_str_with_color("Cyan color text", Color::Cyan);
texts.push_str_with_color("Red color text", Color::Red);
texts.push_str_with_color(", pushed texts become a single String.", Color::Yellow);
texts.push_str_with_color("\n If you want to add break lines, you should add `\n`.", Color::Magenta);
println!("{}", texts);
source

pub fn push_str_with_color_and_attribute<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color,
attr: Attribute
)

Text can be pushed color and attribute to Vector. When color or attribute are different, it will be pushed as different String.

Example
let mut texts = StyledStrings::default();
texts.push_str_with_color_and_attribute("Magenta and bold text\n", Color::Magenta, Attribute::Bold);
texts.push_str_with_color_and_attribute("White and underlined text", Color::White, Attribute::Underline);
// texts.push_str_with_color_and_attribute("Must be specify the color and attribute", None, Attribute::Underline);
println!("{}", texts);
source

pub fn is_empty(&self) -> bool

Determine if all strings in Vec are empty Returns False if any string is present.

Trait Implementations§

source§

impl Debug for StyledStrings

source§

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

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

impl Default for StyledStrings

source§

fn default() -> StyledStrings

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

impl Display for StyledStrings

source§

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

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

impl From<StyledStrings> for String

source§

fn from(s: StyledStrings) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToString for Twhere
T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.