# `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 like `nf-cod-account`
- Accepts hex codepoints:
- `eb99`
- `0xeb99`
- `U+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:
```toml
[dependencies]
nerdle = "1.0.0"
```
## Usage
```rust
use nerdle::{nerd, nerd_char, nerd_cp};
let s1 = nerd!("cod-account");
let s2 = nerd!("nf-cod-account");
let s3 = nerd!("eb99");
let s4 = nerd!("0xeb99");
let s5 = nerd!("U+EB99");
let flexible = nerd!("NF COD ACCOUNT");
let flexible2 = nerd!("cod_account");
let c = nerd_char!("cod-account");
let cp = nerd_cp!("cod-account");
assert_eq!(s1, "");
assert_eq!(s2, "");
assert_eq!(s3, "");
assert_eq!(s4, "");
assert_eq!(s5, "");
assert_eq!(flexible, "");
assert_eq!(flexible2, "");
assert_eq!(c, '');
assert_eq!(cp, 0xeb99);
```
## Macros
### `nerd!`
Returns a `&'static str` containing the resolved glyph.
```rust
let glyph = nerdle::nerd!("cod-account");
```
### `nerd_char!`
Returns the resolved glyph as a `char`.
```rust
let glyph = nerdle::nerd_char!("cod-account");
```
### `nerd_cp!`
Returns the resolved glyph codepoint as a `u32`.
```rust
let codepoint = nerdle::nerd_cp!("cod-account");
```
## Accepted Inputs
### Glyph names
All of the following resolve to the same icon:
```rust
nerdle::nerd!("cod-account");
nerdle::nerd!("nf-cod-account");
nerdle::nerd!("COD ACCOUNT");
nerdle::nerd!("cod_account");
nerdle::nerd!("nf cod account");
```
### Codepoints
The following formats are accepted:
```rust
nerdle::nerd!("eb99");
nerdle::nerd!("0xeb99");
nerdle::nerd!("U+EB99");
```
## 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 macros
- `nerdle-proc-macro`: the proc-macro implementation
During build of the proc-macro crate:
1. `build.rs` reads a vendored `glyphs.json` snapshot
2. it validates that each JSON `char` matches its `code`
3. it checks for normalized-name collisions after case and separator folding
4. it generates a Rust source file in `OUT_DIR`
5. the generated file contains a large `match`-based lookup function
6. the proc macro resolves the user input and emits a literal
That means downstream code gets plain literals like:
```rust
""
''
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:
```bash
cargo test
```
## Testing
The crate includes:
- integration tests for successful lookups
- `trybuild` tests for compile-time diagnostics
Run everything with:
```bash
cargo test
```
## Versioning
This crate follows semantic versioning.
## License
See your repository licensing terms.