csscolorparser

Struct Color

source
pub struct Color {
    pub r: f64,
    pub g: f64,
    pub b: f64,
    pub a: f64,
}
Expand description

The color

Fields§

§r: f64

Red

§g: f64

Green

§b: f64

Blue

§a: f64

Alpha

Implementations§

source§

impl Color

source

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

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

pub fn to_array(&self) -> [f64; 4]

source

pub fn to_rgba8(&self) -> [u8; 4]

source

pub fn to_rgba16(&self) -> [u16; 4]

source

pub fn clamp(&self) -> Self

source

pub fn from_rgb(r: f64, g: f64, b: f64) -> Self

👎Deprecated: Use new instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
source

pub fn from_rgba(r: f64, g: f64, b: f64, a: f64) -> Self

👎Deprecated: Use new instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

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

👎Deprecated: Use from_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
source

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

👎Deprecated: Use from_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

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

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_linear_rgb(r: f64, g: f64, b: f64) -> Self

👎Deprecated: Use from_linear_rgba instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
source

pub fn from_linear_rgba(r: f64, g: f64, b: f64, a: f64) -> Self

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

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

👎Deprecated: Use from_linear_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
source

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

👎Deprecated: Use from_linear_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

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

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_hsv(h: f64, s: f64, v: f64) -> Self

👎Deprecated: Use from_hsva instead.

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
source

pub fn from_hsva(h: f64, s: f64, v: f64, a: f64) -> Self

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
  • a: Alpha [0..1]
source

pub fn from_hsl(h: f64, s: f64, l: f64) -> Self

👎Deprecated: Use from_hsla instead.

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
source

pub fn from_hsla(h: f64, s: f64, l: f64, a: f64) -> Self

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
  • a: Alpha [0..1]
source

pub fn from_hwb(h: f64, w: f64, b: f64) -> Self

👎Deprecated: Use from_hwba instead.

Arguments:

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
source

pub fn from_hwba(h: f64, w: f64, b: f64, a: f64) -> Self

Arguments:

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
  • a: Alpha [0..1]
source

pub fn from_oklab(l: f64, a: f64, b: f64) -> Self

👎Deprecated: Use from_oklaba instead.

Arguments:

  • l: Perceived lightness
  • a: How green/red the color is
  • b: How blue/yellow the color is
source

pub fn from_oklaba(l: f64, a: f64, b: f64, alpha: f64) -> Self

Arguments:

  • l: Perceived lightness
  • a: How green/red the color is
  • b: How blue/yellow the color is
  • alpha: Alpha [0..1]
source

pub fn from_html<S: AsRef<str>>(s: S) -> Result<Self, ParseColorError>

Create color from CSS color string.

§Examples
use csscolorparser::Color;

let c = Color::from_html("rgb(255,0,0)")?;

assert_eq!(c.to_array(), [1.0, 0.0, 0.0, 1.0]);
assert_eq!(c.to_rgba8(), [255, 0, 0, 255]);
assert_eq!(c.to_hex_string(), "#ff0000");
assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");
source

pub fn name(&self) -> Option<&'static str>

source

pub fn rgba(&self) -> (f64, f64, f64, f64)

👎Deprecated

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..1]
source

pub fn rgba_u8(&self) -> (u8, u8, u8, u8)

👎Deprecated: Use to_rgba8 instead.

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..255]
source

pub fn to_hsva(&self) -> (f64, f64, f64, f64)

Returns: (h, s, v, a)

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
  • a: Alpha [0..1]
source

pub fn to_hsla(&self) -> (f64, f64, f64, f64)

Returns: (h, s, l, a)

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
  • a: Alpha [0..1]
source

pub fn to_hwba(&self) -> (f64, f64, f64, f64)

Returns: (h, w, b, a)

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
  • a: Alpha [0..1]
source

pub fn to_linear_rgba(&self) -> (f64, f64, f64, f64)

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..1]
source

pub fn to_linear_rgba_u8(&self) -> (u8, u8, u8, u8)

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..255]
source

pub fn to_oklaba(&self) -> (f64, f64, f64, f64)

Returns: (l, a, b, alpha)

source

pub fn to_hex_string(&self) -> String

Get the RGB hexadecimal color string.

source

pub fn to_rgb_string(&self) -> String

Get the CSS rgb() format string.

source

pub fn interpolate_rgb(&self, other: &Color, t: f64) -> Self

Blend this color with the other one, in the RGB color-space. t in the range [0..1].

source

pub fn interpolate_linear_rgb(&self, other: &Color, t: f64) -> Self

Blend this color with the other one, in the linear RGB color-space. t in the range [0..1].

source

pub fn interpolate_hsv(&self, other: &Color, t: f64) -> Self

Blend this color with the other one, in the HSV color-space. t in the range [0..1].

source

pub fn interpolate_oklab(&self, other: &Color, t: f64) -> Self

Blend this color with the other one, in the Oklab color-space. t in the range [0..1].

Trait Implementations§

source§

impl Clone for Color

source§

fn clone(&self) -> Color

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 Debug for Color

source§

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

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

impl Default for Color

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Color

Implement Serde deserialization from string

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Color

source§

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

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

impl From<[f32; 3]> for Color

source§

fn from([r, g, b]: [f32; 3]) -> Self

Converts to this type from the input type.
source§

impl From<[f32; 4]> for Color

source§

fn from([r, g, b, a]: [f32; 4]) -> Self

Converts to this type from the input type.
source§

impl From<[f64; 3]> for Color

source§

fn from([r, g, b]: [f64; 3]) -> Self

Converts to this type from the input type.
source§

impl From<[f64; 4]> for Color

source§

fn from([r, g, b, a]: [f64; 4]) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 3]> for Color

source§

fn from([r, g, b]: [u8; 3]) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 4]> for Color

source§

fn from([r, g, b, a]: [u8; 4]) -> Self

Converts to this type from the input type.
source§

impl From<(f64, f64, f64)> for Color

source§

fn from((r, g, b): (f64, f64, f64)) -> Self

Converts to this type from the input type.
source§

impl From<(f64, f64, f64, f64)> for Color

source§

fn from((r, g, b, a): (f64, f64, f64, f64)) -> Self

Converts to this type from the input type.
source§

impl From<(u8, u8, u8)> for Color

source§

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

Converts to this type from the input type.
source§

impl From<(u8, u8, u8, u8)> for Color

source§

fn from((r, g, b, a): (u8, u8, u8, u8)) -> Self

Converts to this type from the input type.
source§

impl FromStr for Color

source§

type Err = ParseColorError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
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 · 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 Color

source§

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

Implement Serde serialization into HEX string

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&str> for Color

source§

type Error = ParseColorError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
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 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, 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,