hex_rgb_converter
Dead simple RGB ↔ hex color conversion.
let hex = hex;
let rgb = rgb;
// Convert between representations.
let back_to_hex = rgb.to_hex;
let back_to_rgb = hex.to_rgb;
// Compare across formats.
assert!;
Usage
Add to Cargo.toml:
[]
= "1"
Then use in your code:
use ;
Examples
Hex → RGB
let hex = hex;
let rgb: RgbColor = hex.to_rgb;
println!; // #787878
println!; // (120,120,120)
RGB → Hex
let rgb = rgb;
let hex: HexColor = rgb.to_hex;
println!; // #12ef78
Builder-style mutation
let mut rgb = rgb;
rgb.set_blue
.set_green
.set_red
.set_color;
println!; // (120,120,120)
Named colours
by_name.print; // #ffa500
by_name.print; // #ff7f50
Equality checks
let hex = hex;
let rgb = rgb;
println!; // false (blue ≠ white)
println!; // true
println!; // true
color! macro (optional)
The color! macro dispatches on argument count:
use color;
let a = color!; // calls Color::hex
let b = color!; // calls Color::rgb
This is the only macro provided — use Color::hex() and Color::rgb()
directly when you don't need the shorthand.
License
MIT. See LICENSE.