Expand description
Derive macro for IRI-valued enum types.
Storage and comparison of full IRIs can be costly. For known vocabularies a
plain enum is cheaper. The IriEnum derive generates the glue: conversion
from a borrowed iri_rs_core::Iri into the enum, and back into a
'static-backed iri_rs_core::Iri.
ⓘ
use iri_rs_enum::IriEnum;
use iri_rs_static::iri;
#[derive(IriEnum, PartialEq, Debug)]
#[iri_prefix("schema" = "https://schema.org/")]
pub enum Vocab {
#[iri("schema:name")] Name,
#[iri("schema:knows")] Knows,
}
let term: Vocab = Vocab::try_from(&iri!("https://schema.org/name")).unwrap();
assert_eq!(term, Vocab::Name);Variants with a single unnamed field act as fallbacks; the inner type must
implement TryFrom<&Iri<T>> and From<&Inner> for Iri<&'static str>
(both generated by this derive on nested enums).
Path resolution uses proc_macro_crate: downstream crates can depend on
either iri-rs-core directly or on the iri-rs umbrella crate (which
re-exports the runtime types under a hidden __private module).