urn-rs
A small, allocation-conscious Rust crate for RFC 8141 / RFC 2141 URNs — parse, build, compare, percent-encode.
use ;
let u: Urn = "urn:example:weather/zurich?+ttl=60#frag".parse?;
assert_eq!;
assert_eq!;
let built = new.build?;
assert_eq!;
Why this fork
Fork of urn by chayleaf. RFC behavior unchanged; this fork adds:
- SWAR fast path and hex lookup tables for percent decode/encode.
- Fewer allocations in builder, accessors, setters, serde.
Ord/PartialOrdonUrnandUrnSlice.- Criterion bench suite under
benches/. - Rust 2024 edition, MSRV 1.85.
- Renamed to
urn-rs.
Credit and history preserved — see Attribution.
Install
Feature flags
| Flag | Default | Enables |
|---|---|---|
std |
yes | alloc + std::error::Error impls |
alloc |
Owned Urn, UrnBuilder, String-returning APIs |
|
serde |
Serialize / Deserialize for Urn and UrnSlice |
|
exact-eq |
Include r-/q-/f-components in PartialEq / Ord / Hash (normalized) |
For no_std, disable default features. You get UrnSlice<'a> (borrowed, zero-alloc). Add alloc back for Urn and the builder.
Equivalence
By default, equality compares only the significant portion of the URN:
- NID is ASCII-case-insensitive.
- NSS percent-encoding is normalized before comparison.
- r-/q-/f-components are ignored.
- Per-namespace lexical-equivalence rules from individual RFCs are not applied.
Enable exact-eq when distinct r/q/f components must produce distinct map keys — equality then covers the whole normalized URN.
Benchmarks
Criterion output: target/criterion/.
MSRV
Rust 1.85 (edition 2024).
Attribution
Original crate: urn by chayleaf. Upstream commits are preserved in this repo's history under their original authorship. This fork is a thin layer of performance and ergonomics work on top of their design.
License
Triple-licensed, same as upstream. Pick whichever fits: