palett/convert/
_hex_int.rs1pub fn hex_int(hex: &str) -> u32 {
2 let hex = hex.trim_start_matches('#');
3 return match u32::from_str_radix(hex, 16) {
4 Ok(v) => v,
5 Err(_e) => 0
6 };
7}
8
9#[cfg(test)]
10mod tests {
11 use std::collections::HashMap;
12
13 use crate::convert::_hex_int::hex_int;
14
15 #[test]
16 fn test_convert() {
17 let mut map = HashMap::new();
19 map.insert("black", "#000000");
20 map.insert("RED", "#FF0000");
21 map.insert("GREEN", "#00FF00");
22 map.insert("BLUE", "#0000FF");
23 map.insert("YELLOW", "#FFFF00");
24 map.insert("magenta", "#FF00FF");
25 map.insert("CYAN", "#00FFFF");
26 map.insert("white", "#FFFFFF");
27 for (key, value) in map {
29 println!("{} : {}, {}", key, value, hex_int(value));
30 }
31 }
32}