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 systemaccount: Identifies the owner or account responsible for the resourceroot: A unique identifier for the root of the resource hierarchyparts: 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: PartsImplementations§
Source§impl Ern
impl Ern
Sourcepub fn new(
domain: Domain,
category: Category,
account: Account,
root: EntityRoot,
parts: Parts,
) -> Self
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 componentcategory- The category componentaccount- The account componentroot- The root componentparts- 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")?]),
);Sourcepub fn with_root(root: impl Into<String>) -> Result<Self, ErnError>
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 partsErr(ErnError)- If the root value is invalid
§Example
let ern = Ern::with_root("profile")?;Sourcepub fn with_new_root(
&self,
new_root: impl Into<String>,
) -> Result<Self, ErnError>
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 rootErr(ErnError)- If the new root value is invalid
§Example
let ern1 = Ern::with_root("profile")?;
let ern2 = ern1.with_new_root("settings")?;pub fn with_domain(domain: impl Into<String>) -> Result<Self, ErnError>
pub fn with_category(category: impl Into<String>) -> Result<Self, ErnError>
pub fn with_account(account: impl Into<String>) -> Result<Self, ErnError>
Sourcepub fn add_part(&self, part: impl Into<String>) -> Result<Self, ErnError>
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 partErr(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")?;pub fn with_parts( &self, parts: impl IntoIterator<Item = impl Into<String>>, ) -> Result<Self, ErnError>
Sourcepub fn is_child_of(&self, other: &Ern) -> bool
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:
- They have the same domain, category, account, and root
- The child’s parts start with all of the parent’s parts
- 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 ERNfalse- 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));Sourcepub fn parent(&self) -> Option<Self>
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 ERNNone- 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());