Crate prefix_register

Crate prefix_register 

Source
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 at once
  • PostgreSQL backend - Durable, scalable storage with connection pooling

§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§

BatchStoreResult
Result of a batch store operation.
PrefixRegistry
Registry for namespace prefixes.

Enums§

ConfigurationError
Configuration error types with specific variants.
Error
Error types for prefix registry operations.

Type Aliases§

Result
Result type alias for prefix registry operations.