Expand description
§Prefix Register
Status: Beta - API may change before 1.0 release.
A PostgreSQL-backed namespace prefix registry for CURIE expansion and prefix management.
This library provides bidirectional mapping between namespace prefixes (like “foaf”, “rdf”, “schema”) and their full URI bases, optimised for use in RDF/semantic web applications.
API: Async-only, built on tokio and deadpool-postgres for high concurrency.
§Features
- Async-only - Built on tokio for high concurrency
- In-memory caching - Prefixes loaded on startup for fast CURIE expansion
- First-prefix-wins - Each URI can only have one registered prefix
- Batch operations - Efficiently store multiple prefixes in a single round trip
- PostgreSQL backend - Durable, scalable storage with connection pooling
- Startup resilience - Optional retry with exponential backoff for container orchestration
- Input validation - Prevents DoS via length limits (prefix max 64, URI max 2048 chars)
- Tracing instrumentation - Built-in spans and events for observability
§Use Cases
- CURIE expansion in RDF processing
- Namespace prefix management for semantic web applications
- Prefix discovery from Turtle, JSON-LD, XML documents
§Example
use prefix_register::PrefixRegistry;
#[tokio::main]
async fn main() -> prefix_register::Result<()> {
// Connect to PostgreSQL (schema must have namespaces table)
let registry = PrefixRegistry::new(
"postgres://localhost/mydb",
10, // max connections
).await?;
// Store a prefix (only if URI doesn't already have one)
let stored = registry.store_prefix_if_new("foaf", "http://xmlns.com/foaf/0.1/").await?;
println!("Prefix stored: {}", stored);
// Expand a CURIE
if let Some(uri) = registry.expand_curie("foaf", "Person").await? {
println!("foaf:Person = {}", uri);
}
Ok(())
}Structs§
- Batch
Store Result - Result of a batch store operation.
- Prefix
Registry - Registry for namespace prefixes.
- Retry
Config - Configuration for connection retry behaviour.
Enums§
- Configuration
Error - Configuration error types with specific variants.
- Error
- Error types for prefix registry operations.
Constants§
- MAX_
PREFIX_ LENGTH - Maximum length for a prefix (64 characters).
- MAX_
URI_ LENGTH - Maximum length for a URI (2048 characters).
Type Aliases§
- Result
- Result type alias for prefix registry operations.