| Crates.io | color_sort |
| lib.rs | color_sort |
| version | 0.1.0 |
| created_at | 2025-09-23 00:15:49.379758+00 |
| updated_at | 2025-09-23 00:15:49.379758+00 |
| description | A library for sorting and filtering colors in HEX, RGB(A) and HSL formats. |
| homepage | |
| repository | https://github.com/mxve/color_sort |
| max_upload_size | |
| id | 1850788 |
| size | 28,250 |
A Rust library for sorting and filtering colors in HEX, RGB(A) and HSL formats. This library does not follow any conventions, it justworks™ but may do so differently from what you would expect.
#f00 RGB#f00a RGBA#ff0000 full RGB#ff0000aa full RGBArgb(255,0,0), rgba(255,0,0,0.5)hsl(0,100%,50%)use color_sort::*;
// Parse mixed color formats
let colors = parse_colors(&[
"#f00".to_string(),
"#ff0000".to_string(),
"#ff0000aa".to_string(),
"rgb(0, 255, 0)".to_string(),
"rgba(255, 0, 0, 0.5)".to_string(),
"hsl(240, 100%, 50%)".to_string(),
])?;
// Sort by spectrum (red -> yellow -> green -> cyan -> blue -> magenta)
let mut sorted = colors.clone();
sort_colors(&mut sorted);
// Convert to format
let hex_colors = convert_colors(&colors, TargetFormat::Hex);
// Filter by hue
let filter = FilterOptions::default().with_hues([HueFilter::Red]);
let red_colors = filter_colors(&colors, &filter);
cat examples/colors.json | cargo run --example sort_hex_stdin