2个版本
0.1.1 | 2021年1月3日 |
---|---|
0.1.0 | 2020年4月25日 |
在图像类别中排名第366
4.5MB
8K SLoC
simple-icons-rs
Simple Icons为Rust提供支持。
API与官方JavaScript库相同。
注意。该crate定期生成,理论上应与NPM上的官方库(数据版本)相匹配。
# Cargo.toml
[dependencies]
simple-icons = "2.9.0"
>>> use simple_icons;
>>> println!(simple_icons::get("apple").unwrap());
Icon {
title: "Apple",
slug: "apple",
hex: "999999",
source: "https://worldvectorlogo.com/logo/apple",
svg: "<svg role=\"img\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><title>Apple icon</title><path d=\"M7.078 23.55c-.473-.316-.893-.703-1.244-1.15-.383-.463-.738-.95-1.064-1.454-.766-1.12-1.365-2.345-1.78-3.636-.5-1.502-.743-2.94-.743-4.347 0-1.57.34-2.94 1.002-4.09.49-.9 1.22-1.653 2.1-2.182.85-.53 1.84-.82 2.84-.84.35 0 .73.05 1.13.15.29.08.64.21 1.07.37.55.21.85.34.95.37.32.12.59.17.8.17.16 0 .39-.05.645-.13.145-.05.42-.14.81-.31.386-.14.692-.26.935-.35.37-.11.728-.21 1.05-.26.39-.06.777-.08 1.148-.05.71.05 1.36.2 1.94.42 1.02.41 1.843 1.05 2.457 1.96-.26.16-.5.346-.725.55-.487.43-.9.94-1.23 1.505-.43.77-.65 1.64-.644 2.52.015 1.083.29 2.035.84 2.86.387.6.904 1.114 1.534 1.536.31.21.582.355.84.45-.12.375-.252.74-.405 1.1-.347.807-.76 1.58-1.25 2.31-.432.63-.772 1.1-1.03 1.41-.402.48-.79.84-1.18 1.097-.43.285-.935.436-1.452.436-.35.015-.7-.03-1.034-.127-.29-.095-.576-.202-.856-.323-.293-.134-.596-.248-.905-.34-.38-.1-.77-.148-1.164-.147-.4 0-.79.05-1.16.145-.31.088-.61.196-.907.325-.42.175-.695.29-.855.34-.324.096-.656.154-.99.175-.52 0-1.004-.15-1.486-.45zm6.854-18.46c-.68.34-1.326.484-1.973.436-.1-.646 0-1.31.27-2.037.24-.62.56-1.18 1-1.68.46-.52 1.01-.95 1.63-1.26.66-.34 1.29-.52 1.89-.55.08.68 0 1.35-.25 2.07-.228.64-.568 1.23-1 1.76-.435.52-.975.95-1.586 1.26z\"/></svg>",
path: "M7.078 23.55c-.473-.316-.893-.703-1.244-1.15-.383-.463-.738-.95-1.064-1.454-.766-1.12-1.365-2.345-1.78-3.636-.5-1.502-.743-2.94-.743-4.347 0-1.57.34-2.94 1.002-4.09.49-.9 1.22-1.653 2.1-2.182.85-.53 1.84-.82 2.84-.84.35 0 .73.05 1.13.15.29.08.64.21 1.07.37.55.21.85.34.95.37.32.12.59.17.8.17.16 0 .39-.05.645-.13.145-.05.42-.14.81-.31.386-.14.692-.26.935-.35.37-.11.728-.21 1.05-.26.39-.06.777-.08 1.148-.05.71.05 1.36.2 1.94.42 1.02.41 1.843 1.05 2.457 1.96-.26.16-.5.346-.725.55-.487.43-.9.94-1.23 1.505-.43.77-.65 1.64-.644 2.52.015 1.083.29 2.035.84 2.86.387.6.904 1.114 1.534 1.536.31.21.582.355.84.45-.12.375-.252.74-.405 1.1-.347.807-.76 1.58-1.25 2.31-.432.63-.772 1.1-1.03 1.41-.402.48-.79.84-1.18 1.097-.43.285-.935.436-1.452.436-.35.015-.7-.03-1.034-.127-.29-.095-.576-.202-.856-.323-.293-.134-.596-.248-.905-.34-.38-.1-.77-.148-1.164-.147-.4 0-.79.05-1.16.145-.31.088-.61.196-.907.325-.42.175-.695.29-.855.34-.324.096-.656.154-.99.175-.52 0-1.004-.15-1.486-.45zm6.854-18.46c-.68.34-1.326.484-1.973.436-.1-.646 0-1.31.27-2.037.24-.62.56-1.18 1-1.68.46-.52 1.01-.95 1.63-1.26.66-.34 1.29-.52 1.89-.55.08.68 0 1.35-.25 2.07-.228.64-.568 1.23-1 1.76-.435.52-.975.95-1.586 1.26z",
}
用法 & API
如上所述,simple-icons-rs
的用法与官方库非常相似,唯一的例外是图标标识符(在下一节中描述)。
use simple_icons;
fn main() {
let icon = simple_icons::get("Apple");
match icon {
Some(i) => println!(i),
None => println!("no matching icon"),
}
}
正如您所看到的,get
接受一个图标标题并返回一个Option<Icon>
。然而,如果您编译此代码,您可能会注意到生成的二进制文件...几乎有5 MB。这相当大,尤其是如果您只想使用少数几个图标。
如果您在编译时知道要使用哪些图标,您可以直接导入并引用它以减小输出大小。
use simple_icons;
fn main() {
println!(simple_icons::icons::Apple);
}
编译并运行此代码将打印相同的信息,但输出大小减小到约250 KB——比之前的输出大小小近95%。
标识符
在官方库中,图标通过标题在get
中引用,或通过它们的slug进行单独导入。
例如,1Password变为1password
,.NET
变为dot-net
。
这些可以在官方库中使用,如下所示
const simpleIcons = require('simple-icons');
console.log(simpleIcons.get('.NET'));
// or
const icon = require('simple-icons/icons/dot-net');
console.log(icon);
simple-icons-rs
略有不同,因为我们不能使用那些相同的slug作为Rust中的有效标识符(破折号、数字等无效)。
simple-icons-rs
中的标识符的一些示例
标题(JavaScript + Rust) | slug(JavaScript) | 模块(Rust) | 结构(Rust) |
---|---|---|---|
.NET |
dot-net |
dot_net |
DotNet |
1001Tracklists |
1001tracklists |
onethousandandone_tracklists |
OneThousandAndOneTracklists |
1Password |
1password |
one_password |
OnePassword |
500px |
500px |
五百_px |
FiveHundredPx |
A-框架 |
a-框架 |
a_frame |
AFrame |
苹果 |
apple |
apple |
apple |
AT&T |
at-and-t |
at_and_t |
ATAndT |
D3.js |
d3-dot-js |
d_three_dot_js |
DThreeDotJs |
iFixit |
ifixit |
ifixit |
IFixit |
Nintendo 3DS |
nintendo3ds |
nintendo_three_ds |
NintendoThreeDS |
Picarto.TV |
picarto-dot-tv |
picarto_dot_tv |
PicartoDotTV |
PlayStation4 |
playstation4 |
playstation_four |
PlayStationFour |
SkypeforBusiness |
skypeforbusiness |
skype_for_business |
SkypeForBusiness |
styled-components |
styled-components |
styled_components |
StyledComponents |
TELE5 |
tele5 |
tele_five |
TELEFive |
腾讯QQ |
tencentqq |
tencent_qq |
TencentQQ |
Wii U |
wiiu |
wii_u |
WiiU |
Windows95 |
windows95 |
windows_ninety_five |
WindowsNinetyFive |
许可
TBH有点不确定。
在此存储库中用于生成crate的代码根据The Unlicense许可,但官方库(用于生成crate)根据CC0 1.0许可,因此我将crate作为此类许可。
实际上我认为它们应该相当相似,它们都是对公共领域的贡献,但我不是法律专业人士,也没有对这两种许可证进行“法律差异”比较。