pub trait ColorInfo: ToRgba {
// Provided methods
fn luminance(self) -> f32 { ... }
fn is_light(self) -> bool { ... }
fn contrast_ratio(self, other: impl ToRgba) -> f32 { ... }
fn to_hex(self) -> String { ... }
fn to_bytes(self) -> (u8, u8, u8, u8) { ... }
}Expand description
Trait for computing luminance, contrast, and hex/byte serialization.
This trait has a blanket impl for all ToRgba types, so every color
type gets these methods automatically:
use optic_color::*;
let c = RGB(0.5, 0.2, 0.8);
let lum = c.luminance();
let hex = c.to_hex();
let (r, g, b, a) = c.to_bytes();Provided Methods§
Sourcefn luminance(self) -> f32
fn luminance(self) -> f32
Relative luminance per ITU-R BT.709.
Uses the standard coefficients: 0.2126 R + 0.7152 G + 0.0722 B.
Sourcefn contrast_ratio(self, other: impl ToRgba) -> f32
fn contrast_ratio(self, other: impl ToRgba) -> f32
Compute the WCAG contrast ratio against another color.
The result is a value in 1..21. WCAG AA requires 4.5:1 for normal text; WCAG AAA requires 7:1.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".