rust-rgb icon indicating copy to clipboard operation
rust-rgb copied to clipboard

feature: option to convert color to html code

Open LuckyTurtleDev opened this issue 3 years ago • 2 comments
trafficstars

It would be nice if it will be possible to convert the color to html.

Some thing like this:

let color = RGB8 { r: 255, g: 0, b: 0 };
println("color: {}", color.to_html());
color: #ff0000

LuckyTurtleDev avatar Jul 16 '22 19:07 LuckyTurtleDev

this is pretty easy to implement (code w/o dependency on rgb as it's not available on the playground):

fn main() {
    let rgb = [255 as u8, 2 as u8, 1 as u8];
    println!("RGB ({}, {}, {}) = #{:0>2x}{:0>2x}{:0>2x}", rgb[0], rgb[1], rgb[2], rgb[0], rgb[1], rgb[2]);
}

output:

RGB (255, 2, 1) = #ff0201

see on the playground.

rursprung avatar Jul 02 '23 17:07 rursprung

Related to #1. This seems out of scope of this project.

It is easy to implement for the end user:

pub trait ToHtml {
    fn to_html(&self) -> String;
}
impl ToHtml for Rgb<u8> {
    ...
}

I'd recommend closing this.

ripytide avatar May 23 '24 15:05 ripytide