Expand description
Primitive contrast-ratio helpers.
The helpers here are intentionally small utility calculations. They do not guarantee full compliance outcomes by themselves.
§Examples
use use_contrast::{
ContrastLevel, RgbColor, classify_normal_text, contrast_ratio, passes_normal_text_aaa,
relative_luminance,
};
let black = RgbColor {
red: 0,
green: 0,
blue: 0,
};
let white = RgbColor {
red: 255,
green: 255,
blue: 255,
};
let ratio = contrast_ratio(black, white);
assert!(relative_luminance(white) > relative_luminance(black));
assert!((ratio - 21.0).abs() < 1.0e-12);
assert!(passes_normal_text_aaa(ratio));
assert_eq!(classify_normal_text(ratio).unwrap(), ContrastLevel::AAA);