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 | 0.94 | µs |
| badge-maker | Node.js | 43.7 | µs |
Both render a badge with a Simple Icons logo; cargo bench reproduces the Rust
side. badge-maker takes an already-encoded logo, so it is handed the same data
URI shields resolves internally. Text-only badges render in 0.87 µs, and
rendering takes no locks, so it scales with cores.
Label and message text is XML-escaped at render time, so &, < and quotes in
badge text produce well-formed SVG and cannot escape their attribute or element.
Escaping runs after text measurement, which is why it belongs here and not in
calling code: pre-escaped input would be laid out five characters wide per &.
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.