[−][src]Function csscolorparser::parse
pub fn parse(s: &str) -> Result<Color, ParseError>
Parse CSS color string
Examples
// short hexadecimal format let c = csscolorparser::parse("#ff0").unwrap(); assert_eq!(c.rgba(), (1., 1., 0., 1.)); assert_eq!(c.rgba_u8(), (255, 255, 0, 255)); assert_eq!(c.to_hex_string(), "#ffff00"); assert_eq!(c.to_rgb_string(), "rgb(255,255,0)"); // hsl() format let c = csscolorparser::parse("hsl(360deg,100%,50%)").unwrap(); assert_eq!(c.rgba(), (1., 0., 0., 1.)); assert_eq!(c.rgba_u8(), (255, 0, 0, 255)); assert_eq!(c.to_hex_string(), "#ff0000"); assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");
Supported Format
It support named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(),
hsl(), hsla(), hwb(), and hsv().
------ Example color format
transparent
gold
rebeccapurple
lime
#0f0
#0f0f
#00ff00
#00ff00ff
rgb(0,255,0)
rgb(0% 100% 0%)
rgb(0 255 0 / 100%)
rgba(0,255,0,1)
hsl(120,100%,50%)
hsl(120deg 100% 50%)
hsl(-240 100% 50%)
hsl(-240deg 100% 50%)
hsl(0.3333turn 100% 50%)
hsl(133.333grad 100% 50%)
hsl(2.0944rad 100% 50%)
hsla(120,100%,50%,100%)
hwb(120 0% 0%)
hwb(480deg 0% 0% / 100%)
hsv(120,100%,100%)
hsv(120deg 100% 100% / 100%)