Ern

Struct Ern 

Source
pub struct Ern {
    pub domain: Domain,
    pub category: Category,
    pub account: Account,
    pub root: EntityRoot,
    pub parts: Parts,
}
Expand description

Represents an Entity Resource Name (ERN), which uniquely identifies resources in distributed systems.

An ERN follows the URN format and has the structure: ern:domain:category:account:root/path/to/resource

Each component serves a specific purpose:

  • domain: Classifies the resource (e.g., internal, external, custom domains)
  • category: Specifies the service or category within the system
  • account: Identifies the owner or account responsible for the resource
  • root: A unique identifier for the root of the resource hierarchy
  • parts: Optional path-like structure showing the resource’s position within the hierarchy

ERNs can be k-sortable when using UnixTime or Timestamp ID types, enabling efficient ordering and range queries.

Fields§

§domain: Domain§category: Category§account: Account§root: EntityRoot§parts: Parts

Implementations§

Source§

impl Ern

Source

pub fn new( domain: Domain, category: Category, account: Account, root: EntityRoot, parts: Parts, ) -> Self

Creates a new ERN with the specified components.

§Arguments
  • domain - The domain component
  • category - The category component
  • account - The account component
  • root - The root component
  • parts - The path parts component
§Example
let ern = Ern::new(
    Domain::new("my-app")?,
    Category::new("users")?,
    Account::new("tenant123")?,
    EntityRoot::new("profile".to_string())?,
    Parts::new(vec![Part::new("settings")?]),
);
Source

pub fn with_root(root: impl Into<String>) -> Result<Self, ErnError>

Creates a new ERN with the given root and default values for other components.

This is a convenient way to create an ERN when you only care about the root component.

§Arguments
  • root - The string value for the root component
§Returns
  • Ok(Ern) - The created ERN with default values for domain, category, account, and parts
  • Err(ErnError) - If the root value is invalid
§Example
let ern = Ern::with_root("profile")?;
Source

pub fn with_new_root( &self, new_root: impl Into<String>, ) -> Result<Self, ErnError>

Creates a new ERN based on an existing ERN but with a different root.

This method preserves all other components (domain, category, account, parts) but replaces the root with a new value.

§Arguments
  • new_root - The string value for the new root component
§Returns
  • Ok(Ern) - A new ERN with the updated root
  • Err(ErnError) - If the new root value is invalid
§Example
let ern1 = Ern::with_root("profile")?;
let ern2 = ern1.with_new_root("settings")?;
Source

pub fn with_domain(domain: impl Into<String>) -> Result<Self, ErnError>

Source

pub fn with_category(category: impl Into<String>) -> Result<Self, ErnError>

Source

pub fn with_account(account: impl Into<String>) -> Result<Self, ErnError>

Source

pub fn add_part(&self, part: impl Into<String>) -> Result<Self, ErnError>

Adds a new part to the ERN’s path.

This method creates a new ERN with the same domain, category, account, and root, but with an additional part appended to the path.

§Arguments
  • part - The string value for the new part
§Returns
  • Ok(Ern) - A new ERN with the added part
  • Err(ErnError) - If the part value is invalid or adding it would exceed the maximum of 10 parts
§Example
let ern1 = Ern::with_root("profile")?;
let ern2 = ern1.add_part("settings")?;
let ern3 = ern2.add_part("appearance")?;
Source

pub fn with_parts( &self, parts: impl IntoIterator<Item = impl Into<String>>, ) -> Result<Self, ErnError>

Source

pub fn is_child_of(&self, other: &Ern) -> bool

Checks if this ERN is a child of another ERN.

An ERN is considered a child of another ERN if:

  1. They have the same domain, category, account, and root
  2. The child’s parts start with all of the parent’s parts
  3. The child has more parts than the parent
§Arguments
  • other - The potential parent ERN
§Returns
  • true - If this ERN is a child of the other ERN
  • false - Otherwise
§Example
let parent = Ern::with_root("profile")?.add_part("settings")?;
let child = parent.add_part("appearance")?;

assert!(child.is_child_of(&parent));
assert!(!parent.is_child_of(&child));
Source

pub fn parent(&self) -> Option<Self>

Returns the parent ERN of this ERN, if it exists.

The parent ERN has the same domain, category, account, and root, but with one fewer part in the path. If this ERN has no parts, it has no parent and this method returns None.

§Returns
  • Some(Ern) - The parent ERN
  • None - If this ERN has no parts (and thus no parent)
§Example
let ern1 = Ern::with_root("profile")?;
let ern2 = ern1.add_part("settings")?;
let ern3 = ern2.add_part("appearance")?;

assert_eq!(ern3.parent().unwrap().to_string(), ern2.to_string());
assert_eq!(ern2.parent().unwrap().to_string(), ern1.to_string());
assert!(ern1.parent().is_none());

Trait Implementations§

Source§

impl Add for Ern

Source§

type Output = Ern

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Ern

Source§

fn clone(&self) -> Ern

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ern

Source§

fn default() -> Self

Provides a default ERN using the default values of all its components.

This is primarily used internally and for testing. For creating ERNs in application code, prefer using ErnBuilder or the with_root method.

Source§

impl Display for Ern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Ern

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Ern

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Ern

Source§

fn eq(&self, other: &Ern) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Ern

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Ern

Source§

impl StructuralPartialEq for Ern

Auto Trait Implementations§

§

impl Freeze for Ern

§

impl RefUnwindSafe for Ern

§

impl Send for Ern

§

impl Sync for Ern

§

impl Unpin for Ern

§

impl UnwindSafe for Ern

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.