Crate acton_ern

Source
Expand description

§Acton Entity Resource Name (ERN) Library

acton-ern is a Rust library for working with Entity Resource Names (ERNs), which are structured identifiers used to uniquely identify and manage hierarchical resources across different services and partitions in distributed systems. While ERNs follow the Uniform Resource Name (URN) format defined in RFC 8141, they extend beyond standard URNs by offering additional features like k-sortability and type-safe construction.

§Key Features

  • Structured Resource Naming: Create standardized, hierarchical resource identifiers that are both human-readable and machine-parseable
  • K-Sortable Identifiers: When using UnixTime or Timestamp ID types, ERNs can be efficiently sorted and queried by creation time
  • Content-Addressable IDs: When using SHA1Name ID type, generate deterministic IDs based on content
  • Type-Safe Construction: The builder pattern ensures ERNs are constructed correctly at compile time
  • Flexible ID Types: Choose the right ID type for your use case (time-based ordering or content-based addressing)
  • Hierarchical Relationships: Model parent-child relationships between resources naturally
  • Serialization Support: Serialize and deserialize ERNs to/from JSON and YAML (with the serde feature)

§Crate Structure

  • builder: Type-safe builder pattern for constructing ERNs
  • parser: Tools for parsing ERN strings into structured components
  • model: Component models (Domain, Category, Account, Root, Part)
  • traits: Common traits used across the crate

§Basic Usage

use acton_ern::prelude::*;

// Create a time-ordered, sortable ERN
let ern = ErnBuilder::new()
    .with::<Domain>("my-app")?
    .with::<Category>("users")?
    .with::<Account>("tenant123")?
    .with::<EntityRoot>("profile")?
    .with::<Part>("settings")?
    .build()?;

// Parse an ERN from a string
let ern_str = "ern:my-app:users:tenant123:profile_01h9xz7n2e5p6q8r3t1u2v3w4x/settings";
let parsed_ern = ErnParser::new(ern_str.to_string()).parse()?;

§Serialization/Deserialization

With the serde feature enabled, ERNs can be serialized to and deserialized from formats like JSON and YAML:

// Enable the serde feature in Cargo.toml:
// acton-ern = { version = "1.0.0", features = ["serde"] }

use acton_ern::prelude::*;
use serde_json;

// Create an ERN
let ern = ErnBuilder::new()
    .with::<Domain>("my-app")?
    .with::<Category>("users")?
    .with::<Account>("tenant123")?
    .with::<EntityRoot>("profile")?
    .build()?;

// Serialize to JSON
let json = serde_json::to_string(&ern)?;

// Deserialize from JSON
let deserialized: Ern = serde_json::from_str(&json)?;

Modules§

prelude
The prelude module for acton-ern.

Structs§

Account
Represents an account identifier in the ERN (Entity Resource Name) system.
Category
Represents a category in the ERN (Entity Resource Name) system, typically indicating the service.
Domain
EntityRoot
Represents the root component in an Entity Resource Name (ERN).
Ern
Represents an Entity Resource Name (ERN), which uniquely identifies resources in distributed systems.
ErnBuilder
A type-safe builder for constructing ERN instances.
ErnParser
A parser for converting ERN strings into structured Ern objects.
Part
Parts
Represents a collection of parts in the ERN (Entity Resource Name), handling multiple segments.
SHA1Name
Represents a content-addressable identifier in an Entity Resource Name (ERN).

Traits§

ErnComponent
Represents a component of an Entity Resource Name (ERN).