6 个版本
0.0.6 | 2024年1月9日 |
---|---|
0.0.5 | 2023年12月23日 |
0.0.4 | 2023年7月26日 |
0.0.3 | 2023年6月19日 |
#5 in #hex-color
37KB
884 代码行,不包括注释
all-colors
rust 包,用于将字符串转换为十六进制字符串
get_color_hex
接受一个字符串引用(&str)并返回一个6字符的十六进制字符串。
此函数接受的输入
- 6位十六进制字符串将返回原始的十六进制字符串。
- 3位十六进制字符串将返回6字符的十六进制字符串。
- 从colors.rs中大约750个标准颜色名称列表中的一个。
- 9位十进制字符串,如果超过(0-255),(0-255),(0-255),则使用255。
- 否则将使用sha256散列字符串并取前3个字节。
fn main() {
use all_colors::get_color_hex;
//EXAMPLES:
let color_hex = get_color_hex("aqua").expect("well known color name");
let color_hex2 = get_color_hex("give me something interesting").expect("some random color a4f662");
let color_hex3 = get_color_hex("f20").expect("f00 will return ff2200");
let color_hex4 = get_color_hex("010255001").expect("9 digits will become 0aff01");
println!("aqua is #{}", color_hex);
}
依赖项
~500KB
~11K SLoC