Style

Struct Style 

Source
pub struct Style {
    pub fg: Color,
    pub bg: Color,
    pub underline: Color,
    pub attributes: Attributes,
}
Expand description

A style that can be applied to a value.

Has builder methods for building a style. See crate level docs for examples of these.

Fields§

§fg: Color

Foreground color.

§bg: Color

Background color.

§underline: Color

Underline color.

This sets the color used for underlining when the underline attribute is enabled, but does not enable underlining by itself.

§attributes: Attributes

Attributes such as bold, italic, etc.

Implementations§

Source§

impl Style

Source

pub const fn new() -> Self

Create a new style with no attributes and default colors.

Examples found in repository?
examples/style.rs (line 4)
3fn main() {
4    let my_style = Style::new().bold().blue();
5
6    println!("{}!", "Hello".styled_with(my_style));
7
8    println!(
9        "{}",
10        "Rust Language"
11            .styled_with(my_style)
12            .link("https://rust-lang.org")
13    );
14}
Source

pub const fn is_empty(&self) -> bool

Check if the style is empty.

Source

pub const fn fg(self, color: Color) -> Self

Set the foreground color.

Source

pub const fn bg(self, color: Color) -> Self

Set the background color.

Source

pub const fn underline_colored(self, color: Color) -> Self

Set the underline attribute and color.

Source

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

Set the attributes.

This will not unset any existing attributes.

Source

pub const fn bold(self) -> Self

Set the bold attribute.

Examples found in repository?
examples/style.rs (line 4)
3fn main() {
4    let my_style = Style::new().bold().blue();
5
6    println!("{}!", "Hello".styled_with(my_style));
7
8    println!(
9        "{}",
10        "Rust Language"
11            .styled_with(my_style)
12            .link("https://rust-lang.org")
13    );
14}
Source

pub const fn dim(self) -> Self

Set the dim attribute.

Source

pub const fn italic(self) -> Self

Set the italic attribute.

Source

pub const fn underlined(self) -> Self

Set the underline attribute.

Set the blink attribute.

Source

pub const fn inverted(self) -> Self

Set the inverted attribute.

Source

pub const fn hidden(self) -> Self

Set the hidden attribute.

Source

pub const fn strikethrough(self) -> Self

Set the strikethrough attribute.

Source

pub const fn black(self) -> Self

Set the foreground color to black.

Source

pub const fn on_black(self) -> Self

Set the background color to black.

Source

pub const fn underline_black(self) -> Self

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

Source

pub const fn red(self) -> Self

Set the foreground color to red.

Source

pub const fn on_red(self) -> Self

Set the background color to red.

Source

pub const fn underline_red(self) -> Self

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

Source

pub const fn green(self) -> Self

Set the foreground color to green.

Source

pub const fn on_green(self) -> Self

Set the background color to green.

Source

pub const fn underline_green(self) -> Self

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

Source

pub const fn yellow(self) -> Self

Set the foreground color to yellow.

Source

pub const fn on_yellow(self) -> Self

Set the background color to yellow.

Source

pub const fn underline_yellow(self) -> Self

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

Source

pub const fn blue(self) -> Self

Set the foreground color to blue.

Examples found in repository?
examples/style.rs (line 4)
3fn main() {
4    let my_style = Style::new().bold().blue();
5
6    println!("{}!", "Hello".styled_with(my_style));
7
8    println!(
9        "{}",
10        "Rust Language"
11            .styled_with(my_style)
12            .link("https://rust-lang.org")
13    );
14}
Source

pub const fn on_blue(self) -> Self

Set the background color to blue.

Source

pub const fn underline_blue(self) -> Self

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

Source

pub const fn magenta(self) -> Self

Set the foreground color to magenta.

Source

pub const fn on_magenta(self) -> Self

Set the background color to magenta.

Source

pub const fn underline_magenta(self) -> Self

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

Source

pub const fn cyan(self) -> Self

Set the foreground color to cyan.

Source

pub const fn on_cyan(self) -> Self

Set the background color to cyan.

Source

pub const fn underline_cyan(self) -> Self

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

Source

pub const fn white(self) -> Self

Set the foreground color to white.

Source

pub const fn on_white(self) -> Self

Set the background color to white.

Source

pub const fn underline_white(self) -> Self

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

Source

pub const fn bright_black(self) -> Self

Set the foreground color to bright black.

Source

pub const fn on_bright_black(self) -> Self

Set the background color to bright black.

Source

pub const fn underline_bright_black(self) -> Self

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

Source

pub const fn bright_red(self) -> Self

Set the foreground color to bright red.

Source

pub const fn on_bright_red(self) -> Self

Set the background color to bright red.

Source

pub const fn underline_bright_red(self) -> Self

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

Source

pub const fn bright_green(self) -> Self

Set the foreground color to bright green.

Source

pub const fn on_bright_green(self) -> Self

Set the background color to bright green.

Source

pub const fn underline_bright_green(self) -> Self

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

Source

pub const fn bright_yellow(self) -> Self

Set the foreground color to bright yellow.

Source

pub const fn on_bright_yellow(self) -> Self

Set the background color to bright yellow.

Source

pub const fn underline_bright_yellow(self) -> Self

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

Source

pub const fn bright_blue(self) -> Self

Set the foreground color to bright blue.

Source

pub const fn on_bright_blue(self) -> Self

Set the background color to bright blue.

Source

pub const fn underline_bright_blue(self) -> Self

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

Source

pub const fn bright_magenta(self) -> Self

Set the foreground color to bright magenta.

Source

pub const fn on_bright_magenta(self) -> Self

Set the background color to bright magenta.

Source

pub const fn underline_bright_magenta(self) -> Self

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

Source

pub const fn bright_cyan(self) -> Self

Set the foreground color to bright cyan.

Source

pub const fn on_bright_cyan(self) -> Self

Set the background color to bright cyan.

Source

pub const fn underline_bright_cyan(self) -> Self

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

Source

pub const fn bright_white(self) -> Self

Set the foreground color to bright white.

Source

pub const fn on_bright_white(self) -> Self

Set the background color to bright white.

Source

pub const fn underline_bright_white(self) -> Self

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

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate 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 Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

impl Display for Style

Source§

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

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

impl Hash for Style

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 Ord for Style

Source§

fn cmp(&self, other: &Style) -> 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,

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

impl PartialEq for Style

Source§

fn eq(&self, other: &Style) -> 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 PartialOrd for Style

Source§

fn partial_cmp(&self, other: &Style) -> 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 Copy for Style

Source§

impl Eq for Style

Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

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, dest: *mut u8)

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

Source§

fn styled(self) -> Styled<Self>

Create a new Styled value from this value. Read more
Source§

fn styled_with(self, style: Style) -> Styled<Self>

Create a new Styled value from this value, with an existing style. 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.