Skip to main content

Rgb

Struct Rgb 

Source
pub struct Rgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}
Expand description

A 24-bit sRGB colour.

Fields§

§r: u8

Red channel.

§g: u8

Green channel.

§b: u8

Blue channel.

Implementations§

Source§

impl Rgb

Source

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

Creates a colour from its channels.

Source

pub fn parse_hex(text: &str) -> Option<Self>

Parses #RRGGBB or #RGB, in either letter case.

Source

pub fn mix(self, other: Self, t: f32) -> Self

Blends towards other: t = 0 gives self, t = 1 gives other. t is clamped to 0..=1.

Source

pub fn relative_luminance(self) -> f64

WCAG relative luminance, from 0 (black) to 1 (white).

Source

pub fn contrast_ratio(self, other: Self) -> f64

WCAG contrast ratio between two colours, from 1 to 21.

Source

pub fn oklab(self) -> [f64; 3]

The colour in the OKLab perceptual space as [L, a, b].

Source

pub fn perceptual_distance(self, other: Self) -> f64

Euclidean distance in OKLab. Around 0.02 is barely visible; 0.10 reads as a clearly different colour.

Source

pub fn to_ansi256(self) -> u8

Nearest entry of the xterm 256-colour palette (indices 16..=255).

Source

pub fn to_ansi16(self) -> u8

Nearest of the 16 standard terminal colours (xterm defaults).

Trait Implementations§

Source§

impl Clone for Rgb

Source§

fn clone(&self) -> Rgb

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 Rgb

Source§

impl Debug for Rgb

Source§

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

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

impl Display for Rgb

Source§

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

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

impl Eq for Rgb

Source§

impl From<Rgb> for CellColor

Source§

fn from(color: Rgb) -> Self

A hard-coded colour, written #RRGGBB.

Source§

impl Hash for Rgb

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 PartialEq for Rgb

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rgb

Auto Trait Implementations§

§

impl Freeze for Rgb

§

impl RefUnwindSafe for Rgb

§

impl Send for Rgb

§

impl Sync for Rgb

§

impl Unpin for Rgb

§

impl UnsafeUnpin for Rgb

§

impl UnwindSafe for Rgb

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
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> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.