rustint

Crates.iorustint
lib.rsrustint
version0.1.5
sourcesrc
created_at2024-09-29 23:18:22.808183
updated_at2024-10-03 12:39:00.678042
descriptionLibrary for working with RGB colors
homepage
repositoryhttps://github.com/marshallku/rustint
max_upload_size
id1391161
size22,585
Marshall Ku / 구영표 (marshallku)

documentation

README

Rustint

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.

Features

  • Create RGB colors
  • Interpolate between two colors
  • Convert hexadecimal color strings to RGB
  • Convert RGB colors to hexadecimal strings
  • Error handling for invalid color formats

Installation

Add this to your Cargo.toml:

[dependencies]
rustint = "0.1.0"

Usage

Creating a Color

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();

Interpolating Between Colors

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

Converting to Hex String

let color = Color::new(128, 64, 32);
println!("Hex: {}", color); // Outputs: Hex: #804020

Error Handling

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"),
}

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Commit count: 30

cargo fmt