nerdle
Compile-time Nerd Font glyph lookup macros for Rust.
nerdle resolves Nerd Font glyph names or codepoints into string, char, and u32 literals at compile time with no runtime lookup table.
Features
- Compile-time expansion to plain Rust literals
- Supports canonical glyph names like
cod-account - Supports
nf-aliases likenf-cod-account - Accepts hex codepoints:
eb990xeb99U+EB99
- Flexible name matching:
- case-insensitive
- spaces, underscores, and dashes are treated equivalently
- Uses a vendored JSON snapshot for reproducible offline builds
- No
HashMap,phf, or runtime dependency cost in downstream binaries
Installation
Add nerdle to your project:
[]
= "1.0.0"
Usage
use ;
let s1 = nerd!;
let s2 = nerd!;
let s3 = nerd!;
let s4 = nerd!;
let s5 = nerd!;
let flexible = nerd!;
let flexible2 = nerd!;
let c = nerd_char!;
let cp = nerd_cp!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Macros
nerd!
Returns a &'static str containing the resolved glyph.
let glyph = nerd!;
nerd_char!
Returns the resolved glyph as a char.
let glyph = nerd_char!;
nerd_cp!
Returns the resolved glyph codepoint as a u32.
let codepoint = nerd_cp!;
Accepted Inputs
Glyph names
All of the following resolve to the same icon:
nerd!;
nerd!;
nerd!;
nerd!;
nerd!;
Codepoints
The following formats are accepted:
nerd!;
nerd!;
nerd!;
Compile Errors
Invalid inputs fail at compile time with a helpful error message.
Examples:
- unknown glyph name
- malformed hex codepoint
- invalid Unicode scalar value
- non-string-literal macro argument
How It Works
The workspace contains:
nerdle: the public crate that re-exports the macrosnerdle-proc-macro: the proc-macro implementation
During build of the proc-macro crate:
build.rsreads a vendoredglyphs.jsonsnapshot- it validates that each JSON
charmatches itscode - it checks for normalized-name collisions after case and separator folding
- it generates a Rust source file in
OUT_DIR - the generated file contains a large
match-based lookup function - the proc macro resolves the user input and emits a literal
That means downstream code gets plain literals like:
""
''
0xeb99u32
Reproducibility
nerdle uses a vendored glyph snapshot and does not require network access during normal builds.
If you refresh the vendored JSON in the future, review the generated behavior with:
Testing
The crate includes:
- integration tests for successful lookups
trybuildtests for compile-time diagnostics
Run everything with:
Versioning
This crate follows semantic versioning.
License
See your repository licensing terms.