Rustint is a Rust library for working with RGB colors. It provides a simple and efficient way to create, manipulate, and convert colors in Rust applications.
Add this to your Cargo.toml
:
[dependencies]
rustint = "0.1.0"
use rustint::Color;
let red = Color::new(255, 0, 0);
let blue = Color::new(0, 0, 255);
// or
let red = Color::try_from("#FF0000").unwrap();
let blue = Color::try_from("#0000FF").unwrap();
let red = Color::new(255, 0, 0);
let blue = Color::new(0, 0, 255);
let purple = red.interpolate(&blue, 50.0);
println!("Purple: {}", purple); // Outputs: Purple: #7F007F
let color = Color::new(128, 64, 32);
println!("Hex: {}", color); // Outputs: Hex: #804020
The library provides custom error types for handling invalid color formats:
use rustint::{Color, ColorError};
let result = Color::try_from("#INVALID");
match result {
Ok(color) => println!("Valid color: {}", color),
Err(ColorError::InvalidFormat) => println!("Invalid format"),
Err(ColorError::InvalidHexValue) => println!("Invalid hex value"),
}
Contributions are welcome! Please feel free to submit a Pull Request.