shields.rs
A high-performance badge rendering engine written in Rust, supporting SVG output and font parsing. This project is designed for developers and services that require fast, customizable, and reliable badge generation.
🟢 Bitwise-Identical SVG Output
Not only do we pursue pixel-level similarity, but we also guarantee that the generated SVG string is bitwise-identical to the output returned by shields.io for the same parameters. This ensures absolute compatibility and consistency for all use cases.
⚡️ Fast & Efficient
Over 10x faster than the Node.js badge-maker library, this Rust implementation is optimized for speed and efficiency. It can generate badges in microseconds, making it suitable for high-performance applications and services.
🎨 Supported All Styles & Logos
We support all major badge styles: flat, flat-square, plastic, social and for-the-badge. Each style can be customized with various properties such as label, message, color, logo, and more. You can easily use Simple Icons slugs to set logos for your badges, and we also support custom logos with SVG strings.
Benchmark: Rust vs Node.js badge-maker
| Library | Language | Time per badge | Unit |
|---|---|---|---|
| shields | Rust | 3.69 | µs |
| badge-maker | Node.js | 49.52 | µs |
The benchmark renders badges with a Simple Icons logo and links (cargo bench). Simple text-only badges render in well under 1 µs, and rendering is lock-free, so throughput scales with cores.
Installation
Usage Example
The library provides a chainable API for customizing badges. You can set the label, message, color, and other properties using method chaining:
use BadgeStyle;
use Badge;
Additional options beyond the shields.io URL parameters:
use Badge;
let svg = flat
.label
.message
// Unique id suffix, required when several badges are inlined in one HTML
// page (inline SVGs share the page's id namespace).
.id_suffix
// Widen the logo box (default 14px) for wide logos.
.logo_width
.build;
If you only render text badges or custom SVG logos, disable the embedded Simple Icons set to cut compile time and binary size:
= { = "1", = false }
See examples/server.rs for a dependency-free HTTP badge service using the
serde-friendly BadgeParamsOwned type.
There is also a plain parameter-struct API if you prefer explicit construction:
use ;
let svg = render_badge_svg;
License
This project is licensed under the MIT License. See the LICENSE file for details.
Community & Contact
- GitHub: https://github.com/Jannchie/shields.rs
- Documentation: https://docs.rs/shields
- Author: Jannchie (jannchie@gmail.com)