#hex #hex-color #convert-hex #rgb #conversion #convert

hex_to_rgb

A simple Rust library to convert hex color codes to RGB values

3 releases

new 0.1.2 Oct 31, 2024
0.1.1 Oct 29, 2024
0.1.0 Oct 28, 2024

#598 in Algorithms

Download history 217/week @ 2024-10-24

219 downloads per month

MIT license

5KB

hex_to_rgb

hex_to_rgb is a simple Rust library that converts a hexadecimal color code (in #RRGGBB format) to an RGB tuple ((u8, u8, u8)). This crate is designed for quick, lightweight color conversions, making it useful for applications that work with color manipulation and representation.

Installation

To use hex_to_rgb, add it to your Cargo.toml:

[dependencies] hex_to_rgb = "0.1.0"

Then, in your Rust code:

use hex_to_rgb::hex_to_rgb;

fn main() {
let rgb = hex_to_rgb("#FF5733").unwrap();
println!("The color #FF5733 is represented as RGB {:?}", rgb);
// Outputs: The color #FF5733 is represented as RGB (255, 87, 51)
}

Features

Converts hex color codes (like #RRGGBB) to RGB tuples ((u8, u8, u8)). Lightweight and easy to use. Includes error handling for invalid hex inputs.

License

This project is licensed under the MIT License.

Author

Ben Santora (bensatlantik@gmail.com)

No runtime deps