iri-rs-enum
#[derive(IriEnum)] for IRI-valued enum types, part of the iri-rs workspace. Fork of iref-enum by Timothée Haudebourg — reworked to emit const-friendly output via iri-rs-core's from_raw_parts.
Storing and comparing full IRIs is expensive when you only ever use a known vocabulary. IriEnum turns a plain Rust enum into a two-way map between an Iri and its variant — TryFrom<&Iri<T>> in, From<&Variant> to Iri<&'static str> out.
use Iri;
use IriEnum;
use iri;
let term = try_from.unwrap;
assert_eq!;
let back: = .into;
assert_eq!;
Prefixes resolve at macro expansion. Each variant's IRI is validated once against the real parser in iri-rs-core and emitted as a const from pre-computed component positions — no runtime parsing, no allocation.
Install
Enable the enum feature on the facade crate (recommended):
or depend on this crate directly:
The generated code references ::iri_rs_core::*, so downstream crates must have iri-rs-core as a direct dependency.
Attributes
| Attribute | Where | Meaning |
|---|---|---|
#[iri_prefix("ns" = "https://...")] |
Enum | Declare a prefix usable in #[iri(...)] |
#[iri("ns:term")] |
Variant | IRI for this variant (prefixed or absolute) |
Multiple #[iri_prefix] attributes may be given on the same enum.
Fallback variants
A variant with a single unnamed field acts as a catch-all. The inner type must implement TryFrom<&Iri<T>> and From<&Inner> for Iri<&'static str> — both are generated by this derive on nested enums, so fallbacks compose:
Workspace
Part of the iri-rs workspace. See the root README for the overall picture, motivation, and fork attribution.
MSRV
Rust 1.85 (edition 2024).
License
Dual-licensed: