#hex #color-parser #hex-color #parser #graphics #channel

bin+lib color_parser_lib

A simple hex color parser that supports shorthand and alpha channels

2 releases

Uses new Rust 2024

new 0.1.1 Apr 27, 2025
0.1.0 Apr 27, 2025

#1552 in Parser implementations

34 downloads per month

MIT license

17KB
247 lines

A utility library for parsing and converting colors between different formats.

Supports conversion between:

  • Hexadecimal (#RRGGBB, #RRGGBBAA, #RGB, #RGBA) and Rgba
  • Rgba to Hsl, Hsv, and Cmyk

Example

use color_parser::*;

let rgba = parse_hex_to_rgba("#ff8800").unwrap();
let hsl = parse_rgb_to_hsl(&rgba).unwrap();
let hsv = parse_rgb_to_hsv(&rgba).unwrap();
let cmyk = parse_rgb_to_cmyk(&rgba).unwrap();

Color Parser

A simple and lightweight Rust library to parse hex color codes.

Supports:

  • 3-digit shorthand (#FA3)
  • 4-digit shorthand with alpha (#FA3C)
  • Full hex (#FFAABB)
  • Full hex with alpha (#FFAABBCC)

Usage

use color_parser::parse_hex_color;

let color = parse_hex_color("#FFAABB").unwrap();
println!("{:?}", color); // Rgba { red: 255, green: 170, blue: 187, alpha: 255 }

Features

  • Support for RGBA values
  • Support for shorthand syntax
  • CLI support
  • Support for HSV, HSL, CMYL parsing

Dependencies

~155KB