[][src]Struct text_style::StyledStr

pub struct StyledStr<'a> {
    pub s: &'a str,
    pub style: Option<Style>,
}

A borrowed string with an optional style annotation.

Example

let s = text_style::StyledStr::plain("test").bold();

let s1 = text_style::StyledStr::styled("test", text_style::Style::fg(text_style::AnsiColor::Red.dark()));
let s2 = text_style::StyledStr::plain("test").with(text_style::AnsiColor::Red.dark());
assert_eq!(s1, s2);

Fields

s: &'a str

The content of this string.

style: Option<Style>

The style of this string.

Implementations

impl<'a> StyledStr<'a>[src]

pub fn new(s: &'a str, style: Option<Style>) -> StyledStr<'a>[src]

Creates a new styled string from the given string and an optional style.

pub fn styled(s: &'a str, style: Style) -> StyledStr<'a>[src]

Creates a new styled string from the given string and style.

pub fn plain(s: &'a str) -> StyledStr<'a>[src]

Creates a new styled string from the given string without a style.

pub fn with(self, fg: Color) -> Self[src]

Sets the foreground color for this styled string.

pub fn on(self, bg: Color) -> Self[src]

Sets the background color for this styled string.

pub fn bold(self) -> Self[src]

Sets the bold effect for this styled string.

pub fn italic(self) -> Self[src]

Sets the italic effect for this styled string.

pub fn underline(self) -> Self[src]

Sets the underline effect for this styled string.

pub fn effect(self, effect: Effect) -> Self[src]

Sets the given effect for this styled string.

pub fn style_mut(&mut self) -> &mut Style[src]

Returns a mutable reference to the style of this string, creating a new style with the default settings if the style is currently None.

Trait Implementations

impl<'a> Clone for StyledStr<'a>[src]

impl<'a> Debug for StyledStr<'a>[src]

impl<'a> From<&'a StyledString> for StyledStr<'a>[src]

impl<'a, 'b> From<&'b (Style, &'a str)> for StyledStr<'a>[src]

impl<'a, 'b> From<&'b StyledStr<'a>> for ANSIString<'a>[src]

impl<'a, 'b> From<&'b StyledStr<'a>> for StyledContent<&'a str>[src]

impl<'a, 'b> From<&'b StyledStr<'a>> for StyledString[src]

impl<'a, 'b> From<&'b StyledStr<'a>> for StyledStr<'a>[src]

impl<'a> From<(Style, &'a str)> for StyledStr<'a>[src]

impl<'a> From<StyledStr<'a>> for ANSIString<'a>[src]

impl<'a> From<StyledStr<'a>> for StyledContent<&'a str>[src]

impl<'a> From<StyledStr<'a>> for StyledString[src]

impl<'a> From<StyledStr<'a>> for StyledString[src]

impl<'a> PartialEq<StyledStr<'a>> for StyledStr<'a>[src]

impl<'a> StructuralPartialEq for StyledStr<'a>[src]

impl<'a> Termion for StyledStr<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for StyledStr<'a>

impl<'a> Send for StyledStr<'a>

impl<'a> Sync for StyledStr<'a>

impl<'a> Unpin for StyledStr<'a>

impl<'a> UnwindSafe for StyledStr<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> With for T