css-named-colors

Crates.iocss-named-colors
lib.rscss-named-colors
version1.0.1
created_at2025-02-16 20:04:11.753368+00
updated_at2025-02-16 20:11:01.780818+00
descriptionCSS Named Colors
homepage
repositoryhttps://github.com/swizzard/css-named-colors
max_upload_size
id1558089
size46,982
Sam Raker (swizzard)

documentation

https://docs.rs/css-named-colors

README

CSS Named Colors

Basically what it says on the tin. Conversion to/from names, hex codes, and rgb triples.
No dependencies, no allocations, mostly const.

// parsing
let color = NamedColor::from_name("rebeccapurple").expect("invalid name");
// conversion
assert_eq!("#663399", &color.hex());
assert_eq!(Some((102, 51, 153)), &color.rgb());

// `transparent` is handled reasonably
assert_eq!("transparent", NamedColor::TRANSPARENT.hex());
assert!(NamedColor::TRANSPARENT.rgb().is_none());

// aliases/collisions are handled alphabetically
assert_eq!(NamedColor::AQUA.hex(), NamedColor::CYAN.hex());
assert_eq!(NamedColor::from_hex("#00ffff").unwrap(), NamedColor::AQUA); // _not_ CYAN
Commit count: 3

cargo fmt