Rust library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.
Supported Color Format
Absolute Color
- Named colors
- RGB hexadecimal (with and without
#prefix)- Short format
#rgb - Short format with alpha
#rgba - Long format
#rrggbb - Long format with alpha
#rrggbbaa
- Short format
rgb()andrgba()hsl()andhsla()hwb()lab()lch()oklab()oklch()hwba(),hsv(),hsva()- not in CSS standard.
Relative Color
Example:
rgb(from red r g calc(b + 20))
hwb(from #bad455 calc(h + 35) w b)
hsl(from purple h s l / 0.5)
Usage
Add this to your Cargo.toml
= "0.8"
Examples
Using csscolorparser::parse() function.
let c = parse?;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Using parse() method on &str.
use Color;
let c: Color = "#ff00007f".parse?;
assert_eq!;
assert_eq!;
Features
Default
- std: Using the standard library.
- named-colors: Enables parsing from named colors. Requires
phf.
Default features can be disabled using default-features = false.
Optional
- rust-rgb: Enables converting from
rgbcrate types intoColor. - cint: Enables converting
cintcrate types to and fromColor. - serde: Enables serializing (into HEX string) and deserializing (from any supported string color format) using
serdeframework.
Similar Projects
- csscolorparser (Go)
- csscolorparser (Javascript)