11 releases

0.2.8 Feb 19, 2024
0.2.7 Feb 18, 2024
0.2.5 Jan 17, 2023
0.2.4 Dec 1, 2021
0.1.1 Jan 20, 2019

#121 in Web programming

Download history 2343/week @ 2024-01-01 2253/week @ 2024-01-08 2902/week @ 2024-01-15 2985/week @ 2024-01-22 2778/week @ 2024-01-29 3353/week @ 2024-02-05 3781/week @ 2024-02-12 4687/week @ 2024-02-19 4169/week @ 2024-02-26 3634/week @ 2024-03-04 3853/week @ 2024-03-11 3884/week @ 2024-03-18 4257/week @ 2024-03-25 5318/week @ 2024-04-01 3961/week @ 2024-04-08 4573/week @ 2024-04-15

18,454 downloads per month
Used in 18 crates (11 directly)

MIT/Apache

580KB
6.5K SLoC

css-color

Parse color strings from CSS Color Module Level 4. All legacy sRGB forms are supported:

The none keyword is supported. "Missing" color components behave identically to zero.

Usage

First, add this to your Cargo.toml:

[dependencies]
css-color = "0.2.8"

Example

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());
}

Supported Rust Versions

The minimum supported Rust version is 1.55. Earlier versions may compile but parsing can reject certain valid numeric values.

License

This repository is licensed under either of

at your option.

Contributions

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.

No runtime deps