csscolorparser

Struct Color

Source
pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}
Expand description

The color

Fields§

§r: f32

Red

§g: f32

Green

§b: f32

Blue

§a: f32

Alpha

Implementations§

Source§

impl Color

Source

pub const fn new(r: f32, g: f32, b: f32, a: f32) -> 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) -> [f32; 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: f32, g: f32, b: f32) -> 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: f32, g: f32, b: f32, a: f32) -> 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: f32, g: f32, b: f32) -> 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: f32, g: f32, b: f32, a: f32) -> 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: f32, s: f32, v: f32) -> 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: f32, s: f32, v: f32, a: f32) -> 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: f32, s: f32, l: f32) -> 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: f32, s: f32, l: f32, a: f32) -> 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: f32, w: f32, b: f32) -> 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: f32, w: f32, b: f32, a: f32) -> 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: f32, a: f32, b: f32) -> 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: f32, a: f32, b: f32, alpha: f32) -> 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_oklcha(l: f32, c: f32, h: f32, alpha: f32) -> Self

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) -> (f32, f32, f32, f32)

👎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) -> [f32; 4]

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) -> [f32; 4]

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) -> [f32; 4]

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) -> [f32; 4]

Returns: [r, g, b, a]

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

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

Returns: [r, g, b, a]

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

pub fn to_oklaba(&self) -> [f32; 4]

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: f32) -> 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: f32) -> 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: f32) -> 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: f32) -> 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<(f32, f32, f32)> for Color

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from((r, g, b, a): (f32, f32, f32, f32)) -> 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 u8)

🔬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§

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