| Crates.io | css-color |
| lib.rs | css-color |
| version | 0.2.8 |
| created_at | 2019-01-20 08:56:22.733123+00 |
| updated_at | 2024-02-19 21:23:12.060526+00 |
| description | Rust library for CSS color strings |
| homepage | |
| repository | https://github.com/kalcutter/rust-css-color |
| max_upload_size | |
| id | 109640 |
| size | 1,651,852 |
Parse color strings from CSS Color Module Level 4. All legacy sRGB forms are supported:
rgb() and rgba() functions.hsl() and hsla() functions.hwb() function.transparent keyword.The none keyword is supported. "Missing" color components behave identically to zero.
First, add this to your Cargo.toml:
[dependencies]
css-color = "0.2.8"
use css_color::Srgb;
fn main() {
let lime = Srgb::new(0., 1., 0., 1.);
assert_eq!(lime, "#0f0".parse().unwrap());
assert_eq!(lime, "rgb(0 255 0)".parse().unwrap());
assert_eq!(lime, "rgb(0% 100% 0%)".parse().unwrap());
assert_eq!(lime, "hsl(120deg 100% 50% / 100%)".parse().unwrap());
assert_eq!(lime, "hwb(120 0% 0% / 1)".parse().unwrap());
assert_eq!(lime, "lime".parse().unwrap());
}
The minimum supported Rust version is 1.55. Earlier versions may compile but parsing can reject certain valid numeric values.
This repository is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.