Skip to main content

Color

Enum Color 

Source
pub enum Color {
Show 17 variants Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, BrightBlack, BrightRed, BrightGreen, BrightYellow, BrightBlue, BrightMagenta, BrightCyan, BrightWhite, Rgb(u8, u8, u8),
}
Expand description

Terminal color definitions.

Supports both standard 16-color palette and 24-bit RGB colors.

§Color Palette

Standard colors (0-7):

Black   Red     Green   Yellow
Blue    Magenta Cyan    White

Bright colors (8-15):

BrightBlack   BrightRed     BrightGreen   BrightYellow
BrightBlue    BrightMagenta BrightCyan    BrightWhite

Variants§

§

Black

Standard black (color 0)

§

Red

Standard red (color 1)

§

Green

Standard green (color 2)

§

Yellow

Standard yellow (color 3)

§

Blue

Standard blue (color 4)

§

Magenta

Standard magenta (color 5)

§

Cyan

Standard cyan (color 6)

§

White

Standard white (color 7)

§

BrightBlack

Bright black / dark gray (color 8)

§

BrightRed

Bright red (color 9)

§

BrightGreen

Bright green (color 10)

§

BrightYellow

Bright yellow (color 11)

§

BrightBlue

Bright blue (color 12)

§

BrightMagenta

Bright magenta (color 13)

§

BrightCyan

Bright cyan (color 14)

§

BrightWhite

Bright white (color 15)

§

Rgb(u8, u8, u8)

24-bit RGB color (requires terminal support)

Implementations§

Source§

impl Color

Source

pub fn from_hex(hex: &str) -> Result<Self, &'static str>

Creates a Color from a hex string.

Supports multiple formats:

  • 1 digit: "F" or "#F" → grayscale RGB(255, 255, 255)
  • 3 digits: "F53" or "#F53" → RGB(255, 85, 51)
  • 6 digits: "FF5733" or "#FF5733" → RGB(255, 87, 51)

The # prefix is optional. Parsing is case-insensitive.

§Examples
let white = Color::from_hex("#F")?;      // RGB(255, 255, 255)
let gray = Color::from_hex("8")?;        // RGB(136, 136, 136)
let red = Color::from_hex("#F00")?;      // RGB(255, 0, 0)
let orange = Color::from_hex("#FF5733")?; // RGB(255, 87, 51)
Source

pub fn hex(hex: &str) -> Self

Creates a Color from a hex string, panicking on invalid input.

This is a convenience method for use with compile-time constants where you know the hex string is valid.

§Examples
const BRAND_COLOR: Color = Color::hex("#FF5733");
const WHITE: Color = Color::hex("F");
§Panics

Panics if the hex string is invalid.

Source

pub fn rgb(r: u8, g: u8, b: u8) -> Self

Creates an RGB color from individual red, green, and blue components.

This is a convenience constructor that’s equivalent to using the Color::Rgb variant directly.

§Examples
let orange = Color::rgb(255, 165, 0);

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Color

Source§

impl Debug for Color

Source§

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

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

impl Eq for Color

Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

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> Message for T
where T: Any + Clone + Send + Sync + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn clone_box(&self) -> Box<dyn Message>

Source§

impl<T> State for T
where T: Any + Clone + Send + Sync + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn clone_box(&self) -> Box<dyn State>

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, 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.