shields.rs
A badge rendering engine in Rust, compatible with shields.io.
For the same parameters, the generated SVG string is byte-identical to what
shields.io returns — verified against 5,761 reference SVGs fetched from the
live service, covering all five styles (flat, flat-square, plastic,
social, for-the-badge), colors, links, and logos. A weekly CI job re-checks
against upstream, so divergence is caught when shields.io changes its output.
Logos take Simple Icons slugs or raw SVG strings. Font metrics are embedded at compile time; rendering does no I/O, takes no locks, and needs no runtime besides the standard library (wasm32 builds work).
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).
Text-only badges render in well under 1 µs, and lock-free rendering scales with
cores.
Installation
Usage
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;
Documentation
API reference: docs.rs/shields
License
MIT. See LICENSE.