Struct stylic::Styled

source ·
pub struct Styled<T> {
    pub value: T,
    pub style: Style,
}
Expand description

A styled value that implements Display.

See style for a convenient way to create a Styled. There is also style_format if you need to style a format string. See Stylize for available styling options.

Fields§

§value: T§style: Style

Implementations§

source§

impl<T> Styled<T>

source

pub fn apply(self, style: Style) -> Self

Apply a style, overwriting any existing style.

Examples found in repository?
examples/style.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let my_style = Style::new().bold().blue();

    println!("{}!", style("Hello").apply(my_style));

    println!(
        "{}",
        style("Rust Language")
            .apply(my_style)
            .link("https://rust-lang.org")
    );
}

Convert this Styled into a StyledLink.

Examples found in repository?
examples/style.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let my_style = Style::new().bold().blue();

    println!("{}!", style("Hello").apply(my_style));

    println!(
        "{}",
        style("Rust Language")
            .apply(my_style)
            .link("https://rust-lang.org")
    );
}

Trait Implementations§

source§

impl<T: Binary> Binary for Styled<T>

source§

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

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

impl<T: Clone> Clone for Styled<T>

source§

fn clone(&self) -> Styled<T>

Returns a copy 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<T: Default> Default for Styled<T>

source§

fn default() -> Styled<T>

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

impl<T: Display> Display for Styled<T>

source§

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

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

impl<T: Hash> Hash for Styled<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: LowerExp> LowerExp for Styled<T>

source§

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

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

impl<T: LowerHex> LowerHex for Styled<T>

source§

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

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

impl<T: Octal> Octal for Styled<T>

source§

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

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

impl<T: Ord> Ord for Styled<T>

source§

fn cmp(&self, other: &Styled<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq> PartialEq for Styled<T>

source§

fn eq(&self, other: &Styled<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd> PartialOrd for Styled<T>

source§

fn partial_cmp(&self, other: &Styled<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Pointer> Pointer for Styled<T>

source§

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

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

impl<T> Stylize for Styled<T>

source§

fn fg(self, color: impl Into<Color>) -> Self

Set the foreground color.
source§

fn bg(self, color: impl Into<Color>) -> Self

Set the background color.
source§

fn underline_colored(self, color: impl Into<Color>) -> Self

Set the underline attribute and color.
source§

fn attributes(self, attrs: Attributes) -> Self

Set the attributes. Read more
source§

fn bold(self) -> Self

Set the bold attribute.
source§

fn dim(self) -> Self

Set the dim attribute.
source§

fn italic(self) -> Self

Set the italic attribute.
source§

fn underline(self) -> Self

Set the underline attribute.
Set the blink attribute.
source§

fn reverse(self) -> Self

Set the reverse attribute.
source§

fn hidden(self) -> Self

Set the hidden attribute.
source§

fn strikethrough(self) -> Self

Set the strikethrough attribute.
source§

fn black(self) -> Self

Set the foreground color to black.
source§

fn on_black(self) -> Self

Set the background color to black.
source§

fn underline_black(self) -> Self

Set the underline attribute, and set the underline color to black.
source§

fn red(self) -> Self

Set the foreground color to red.
source§

fn on_red(self) -> Self

Set the background color to red.
source§

fn underline_red(self) -> Self

Set the underline attribute, and set the underline color to red.
source§

fn green(self) -> Self

Set the foreground color to green.
source§

fn on_green(self) -> Self

Set the background color to green.
source§

fn underline_green(self) -> Self

Set the underline attribute, and set the underline color to green.
source§

fn yellow(self) -> Self

Set the foreground color to yellow.
source§

fn on_yellow(self) -> Self

Set the background color to yellow.
source§

fn underline_yellow(self) -> Self

Set the underline attribute, and set the underline color to yellow.
source§

fn blue(self) -> Self

Set the foreground color to blue.
source§

fn on_blue(self) -> Self

Set the background color to blue.
source§

fn underline_blue(self) -> Self

Set the underline attribute, and set the underline color to blue.
source§

fn magenta(self) -> Self

Set the foreground color to magenta.
source§

fn on_magenta(self) -> Self

Set the background color to magenta.
source§

fn underline_magenta(self) -> Self

Set the underline attribute, and set the underline color to magenta.
source§

fn cyan(self) -> Self

Set the foreground color to cyan.
source§

fn on_cyan(self) -> Self

Set the background color to cyan.
source§

fn underline_cyan(self) -> Self

Set the underline attribute, and set the underline color to cyan.
source§

fn white(self) -> Self

Set the foreground color to white.
source§

fn on_white(self) -> Self

Set the background color to white.
source§

fn underline_white(self) -> Self

Set the underline attribute, and set the underline color to white.
source§

fn bright_black(self) -> Self

Set the foreground color to bright black.
source§

fn on_bright_black(self) -> Self

Set the background color to bright black.
source§

fn underline_bright_black(self) -> Self

Set the underline attribute, and set the underline color to bright black.
source§

fn bright_red(self) -> Self

Set the foreground color to bright red.
source§

fn on_bright_red(self) -> Self

Set the background color to bright red.
source§

fn underline_bright_red(self) -> Self

Set the underline attribute, and set the underline color to bright red.
source§

fn bright_green(self) -> Self

Set the foreground color to bright green.
source§

fn on_bright_green(self) -> Self

Set the background color to bright green.
source§

fn underline_bright_green(self) -> Self

Set the underline attribute, and set the underline color to bright green.
source§

fn bright_yellow(self) -> Self

Set the foreground color to bright yellow.
source§

fn on_bright_yellow(self) -> Self

Set the background color to bright yellow.
source§

fn underline_bright_yellow(self) -> Self

Set the underline attribute, and set the underline color to bright yellow.
source§

fn bright_blue(self) -> Self

Set the foreground color to bright blue.
source§

fn on_bright_blue(self) -> Self

Set the background color to bright blue.
source§

fn underline_bright_blue(self) -> Self

Set the underline attribute, and set the underline color to bright blue.
source§

fn bright_magenta(self) -> Self

Set the foreground color to bright magenta.
source§

fn on_bright_magenta(self) -> Self

Set the background color to bright magenta.
source§

fn underline_bright_magenta(self) -> Self

Set the underline attribute, and set the underline color to bright magenta.
source§

fn bright_cyan(self) -> Self

Set the foreground color to bright cyan.
source§

fn on_bright_cyan(self) -> Self

Set the background color to bright cyan.
source§

fn underline_bright_cyan(self) -> Self

Set the underline attribute, and set the underline color to bright cyan.
source§

fn bright_white(self) -> Self

Set the foreground color to bright white.
source§

fn on_bright_white(self) -> Self

Set the background color to bright white.
source§

fn underline_bright_white(self) -> Self

Set the underline attribute, and set the underline color to bright white.
source§

impl<T: UpperExp> UpperExp for Styled<T>

source§

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

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

impl<T: UpperHex> UpperHex for Styled<T>

source§

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

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

impl<T: Copy> Copy for Styled<T>

source§

impl<T: Eq> Eq for Styled<T>

source§

impl<T> StructuralPartialEq for Styled<T>

Auto Trait Implementations§

§

impl<T> Freeze for Styled<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Styled<T>
where T: RefUnwindSafe,

§

impl<T> Send for Styled<T>
where T: Send,

§

impl<T> Sync for Styled<T>
where T: Sync,

§

impl<T> Unpin for Styled<T>
where T: Unpin,

§

impl<T> UnwindSafe for Styled<T>
where T: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where 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 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.