Enum cssparser::Color

source ·
pub enum Color {
    CurrentColor,
    Rgba(RGBA),
    Hsl(Hsl),
    Hwb(Hwb),
    Lab(Lab),
    Lch(Lch),
    Oklab(Oklab),
    Oklch(Oklch),
    ColorFunction(ColorFunction),
}
Expand description

Describes one of the value values according to the CSS specification.

Most components are Option<_>, so when the value is None, that component serializes to the “none” keyword.

https://drafts.csswg.org/css-color-4/#color-type

Variants§

§

CurrentColor

The ‘currentcolor’ keyword.

§

Rgba(RGBA)

Specify sRGB colors directly by their red/green/blue/alpha chanels.

§

Hsl(Hsl)

Specifies a color in sRGB using hue, saturation and lightness components.

§

Hwb(Hwb)

Specifies a color in sRGB using hue, whiteness and blackness components.

§

Lab(Lab)

Specifies a CIELAB color by CIE Lightness and its a- and b-axis hue coordinates (red/green-ness, and yellow/blue-ness) using the CIE LAB rectangular coordinate model.

§

Lch(Lch)

Specifies a CIELAB color by CIE Lightness, Chroma, and hue using the CIE LCH cylindrical coordinate model.

§

Oklab(Oklab)

Specifies an Oklab color by Oklab Lightness and its a- and b-axis hue coordinates (red/green-ness, and yellow/blue-ness) using the Oklab rectangular coordinate model.

§

Oklch(Oklch)

Specifies an Oklab color by Oklab Lightness, Chroma, and hue using the OKLCH cylindrical coordinate model.

§

ColorFunction(ColorFunction)

Specifies a color in a predefined color space.

Implementations§

source§

impl Color

source

pub fn parse<'i>( input: &mut Parser<'i, '_> ) -> Result<Color, ParseError<'i, ()>>

Parse a value, per CSS Color Module Level 3.

FIXME(#2) Deprecated CSS2 System Colors are not supported yet.

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

source§

fn from_current_color() -> Self

Construct a new color from the CSS currentcolor keyword.
source§

fn from_rgba( red: Option<u8>, green: Option<u8>, blue: Option<u8>, alpha: Option<f32> ) -> Self

Construct a new color from red, green, blue and alpha components.
source§

fn from_hsl( hue: Option<f32>, saturation: Option<f32>, lightness: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from hue, saturation, lightness and alpha components.
source§

fn from_hwb( hue: Option<f32>, blackness: Option<f32>, whiteness: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from hue, blackness, whiteness and alpha components.
source§

fn from_lab( lightness: Option<f32>, a: Option<f32>, b: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from the lab notation.
source§

fn from_lch( lightness: Option<f32>, chroma: Option<f32>, hue: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from the lch notation.
source§

fn from_oklab( lightness: Option<f32>, a: Option<f32>, b: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from the oklab notation.
source§

fn from_oklch( lightness: Option<f32>, chroma: Option<f32>, hue: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color from the oklch notation.
source§

fn from_color_function( color_space: PredefinedColorSpace, c1: Option<f32>, c2: Option<f32>, c3: Option<f32>, alpha: Option<f32> ) -> Self

Construct a new color with a predefined color space.
source§

impl PartialEq<Color> for Color

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToCss for Color

source§

fn to_css<W>(&self, dest: &mut W) -> Resultwhere W: Write,

Serialize self in CSS syntax, writing to dest.
source§

fn to_css_string(&self) -> String

Serialize self in CSS syntax and return a string. Read more
source§

impl Copy for Color

source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.