#rgba #interpolation #gradient #color #compile-time

color-gradient

Color gradient and color interpolation

4 releases

0.1.3 May 4, 2023
0.1.2 Apr 27, 2023
0.1.1 Mar 28, 2023
0.0.0 Mar 27, 2023

#10 in #rgba

21 downloads per month

MPL-2.0 license

96KB
1.5K SLoC

Rust Color

Compile time color parsing

use color::{rgba, RGBA};

#[test]
fn test_rgba() {
    assert_eq!(rgba!("#334D6677"), RGBA::new(51, 76, 102));
    assert_eq!(rgba!("rgba(51, 77, 102, .5)"), RGBA::new(51, 77, 102, 127));
    assert_eq!(rgba!("rgba(20% 30% 40% 50%)"), RGBA::new(51, 77, 102, 127));
}

success

Compile time error report

// Invalid hex pattern, can take 3,4,6,8 hex number only
rgba!("#34678");

failure

Strict check mode

features = ["strict"]

Normally valid mode is looser than specified, strict mode rejects all non-css level3 input

// will not panic by default
rgba!("rgba(10 10 10, 10)");

Dependencies

~0.4–1.5MB
~25K SLoC