Crates.io | rustint |
lib.rs | rustint |
version | 0.1.5 |
source | src |
created_at | 2024-09-29 23:18:22.808183 |
updated_at | 2024-10-03 12:39:00.678042 |
description | Library for working with RGB colors |
homepage | |
repository | https://github.com/marshallku/rustint |
max_upload_size | |
id | 1391161 |
size | 22,585 |
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.