pub enum CssColor {
CurrentColor,
RGBA(RGBA),
LAB(Box<LABColor>),
Predefined(Box<PredefinedColor>),
Float(Box<FloatColor>),
}
Expand description
A CSS <color>
value.
CSS supports many different color spaces to represent colors. The most common values
are stored as RGBA using a single byte per component. Less common values are stored
using a Box
to reduce the amount of memory used per color.
Each color space is represented as a struct that implements the From
and Into
traits
for all other color spaces, so it is possible to convert between color spaces easily.
In addition, colors support interpolation as in the color-mix()
function.
Variants
CurrentColor
The currentColor
keyword.
RGBA(RGBA)
An value in the RGB color space, including values parsed as hex colors, or the rgb()
, hsl()
, and hwb()
functions.
LAB(Box<LABColor>)
A value in a LAB color space, including the lab()
, lch()
, oklab()
, and oklch()
functions.
Predefined(Box<PredefinedColor>)
A value in a predefined color space, e.g. display-p3
.
Float(Box<FloatColor>)
A floating point representation of an RGB, HSL, or HWB color when it contains none
components.
Implementations
sourceimpl CssColor
impl CssColor
sourcepub fn current_color() -> CssColor
pub fn current_color() -> CssColor
Returns the currentColor
keyword.
sourcepub fn transparent() -> CssColor
pub fn transparent() -> CssColor
Returns the transparent
keyword.
sourcepub fn get_necessary_fallbacks(&self, targets: Browsers) -> ColorFallbackKind
pub fn get_necessary_fallbacks(&self, targets: Browsers) -> ColorFallbackKind
Returns the color fallback types needed for the given browser targets.
sourcepub fn get_fallback(&self, kind: ColorFallbackKind) -> CssColor
pub fn get_fallback(&self, kind: ColorFallbackKind) -> CssColor
Returns a fallback color for the given fallback type.
sourceimpl CssColor
impl CssColor
sourcepub fn interpolate<'a, T>(
&'a self,
p1: f32,
other: &'a CssColor,
p2: f32,
method: HueInterpolationMethod
) -> CssColor where
T: 'static + From<&'a CssColor> + Interpolate + Into<CssColor> + Into<OKLCH> + ColorGamut + Into<OKLAB> + From<OKLCH> + Copy,
pub fn interpolate<'a, T>(
&'a self,
p1: f32,
other: &'a CssColor,
p2: f32,
method: HueInterpolationMethod
) -> CssColor where
T: 'static + From<&'a CssColor> + Interpolate + Into<CssColor> + Into<OKLCH> + ColorGamut + Into<OKLAB> + From<OKLCH> + Copy,
Mixes this color with another color, including the specified amount of each.
Implemented according to the color-mix()
function.
Trait Implementations
sourceimpl From<&CssColor> for SRGBLinear
impl From<&CssColor> for SRGBLinear
sourcefn from(color: &CssColor) -> SRGBLinear
fn from(color: &CssColor) -> SRGBLinear
Converts to this type from the input type.
sourceimpl From<SRGBLinear> for CssColor
impl From<SRGBLinear> for CssColor
sourcefn from(color: SRGBLinear) -> CssColor
fn from(color: SRGBLinear) -> CssColor
Converts to this type from the input type.
sourceimpl<'i> Parse<'i> for CssColor
impl<'i> Parse<'i> for CssColor
sourcefn parse<'t>(
input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i, ParserError<'i>>>
fn parse<'t>(
input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i, ParserError<'i>>>
Parse a value of this type using an existing parser.
sourcefn parse_string(input: &'i str) -> Result<Self, ParseError<'i, ParserError<'i>>>
fn parse_string(input: &'i str) -> Result<Self, ParseError<'i, ParserError<'i>>>
Parse a value from a string. Read more
sourceimpl PartialEq<CssColor> for CssColor
impl PartialEq<CssColor> for CssColor
sourceimpl ToCss for CssColor
impl ToCss for CssColor
sourcefn to_css<W>(
&self,
dest: &mut Printer<'_, '_, '_, W>
) -> Result<(), PrinterError> where
W: Write,
fn to_css<W>(
&self,
dest: &mut Printer<'_, '_, '_, W>
) -> Result<(), PrinterError> where
W: Write,
Serialize self
in CSS syntax, writing to dest
.
sourcefn to_css_string(
&self,
options: PrinterOptions<'_>
) -> Result<String, PrinterError>
fn to_css_string(
&self,
options: PrinterOptions<'_>
) -> Result<String, PrinterError>
Serialize self
in CSS syntax and return a string. Read more
impl StructuralPartialEq for CssColor
Auto Trait Implementations
impl RefUnwindSafe for CssColor
impl Send for CssColor
impl Sync for CssColor
impl Unpin for CssColor
impl UnwindSafe for CssColor
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer