This week I’ve published a Rust library of color data structures, converters, comparators, and arithmetic operators. Check the documentation for detailed getting started and usage instructions, the source code is available on GitHub. What follows is the TLDR for installation and usage…

Cargo.toml (snip)

[dependencies]
color-operators = "0.0.1"

src/main.rs (example)

extern crate color_operators;

use color_operators::color::Color;
use color_operators::hsl::HSL;
use color_operators::hsv::HSV;
use color_operators::rgb::RGB;


fn main() {
    let c = Color::new_rgb(255, 42, 90);
    assert_eq!(c, RGB::new(255, 42, 90));

    let hsv: HSV = c.clone().into():
    let hsl: HSL = c.clone().into():

    assert_eq!(hsv, hsl);
}

Application examples may be run by cloning the repository from GitHub

Clone

mkdir -vp ~/git/hub/rust-utilities

cd ~/git/hub/rust-utilities

git clone git@github.com:rust-utilities/color-operators.git

cd color-operators

Code within the examples/ directory may be run via cargo run --example <name> -- <arguments>

cargo run --example rgb-to-hsl -- -r 255
#> HSL { hue: 0.0, saturation: 1.0, lightness: 0.5 }

cargo run --example rgb-to-hsv -- -g 255
#> HSV { hue: 120.0, saturation: 1.0, value: 1.0 }