Skip to content

Instantly share code, notes, and snippets.

@lunandd
Last active June 30, 2021 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunandd/c79a80e1531060dd623c5428199eb293 to your computer and use it in GitHub Desktop.
Save lunandd/c79a80e1531060dd623c5428199eb293 to your computer and use it in GitHub Desktop.
fn main() {
println!("{}", rgb_to_hex(171, 205, 239));
}
fn rgb_to_hex(r: u8, g: u8, b: u8) -> String {
let mut hex: String = "".into();
let rgb_colors: [u8; 3] = [r, g, b];
for color in rgb_colors.iter() {
hex.push_str( &(format!("{:02x?}", color)) )
}
"#".to_owned() + &hex
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment