Skip to main content

EntityRoot

Struct EntityRoot 

Source
pub struct EntityRoot { /* private fields */ }
Expand description

Represents the root component in an Entity Resource Name (ERN).

The root component is a unique identifier for the base resource in the ERN hierarchy. It uses the mti crate’s MagicTypeId with UUID v7 algorithm to generate time-ordered, unique identifiers that enable k-sortability.

When using EntityRoot, each call to create a new root from a bare name will generate a different ID, as it incorporates the current timestamp. This makes EntityRoot suitable for resources that should be ordered by creation time. A value that is already a fully-formed identifier (for example one taken from an existing ERN) is preserved as-is rather than reissued, so ERNs round-trip through parsing and serialization unchanged.

For content-addressable, deterministic IDs, use SHA1Name instead.

Implementations§

Source§

impl EntityRoot

Source

pub fn name(&self) -> &MagicTypeId

Returns a reference to the underlying MagicTypeId.

This is useful when you need to access the raw identifier for comparison or sorting operations.

§Example
let root1 = EntityRoot::new("resource1".to_string())?;
let root2 = EntityRoot::new("resource2".to_string())?;

// Compare roots by their MagicTypeId
let comparison = root1.name().cmp(root2.name());
Source

pub fn as_str(&self) -> &str

Returns the string representation of this root’s identifier.

§Example
let root = EntityRoot::new("profile".to_string())?;
let id_str = root.as_str();

// The string will contain the original name followed by a timestamp-based suffix
assert!(id_str.starts_with("profile_"));
Source

pub fn name_str(&self) -> &str

Returns the human-readable name of this root, without the generated suffix.

Where as_str yields the full identifier (worker_01h455vb4pex…), this yields just the name it was created from (worker). That name is stable across roots minted from the same input, which makes it the right value to derive a deterministic child path from:

let parent = Ern::with_root("pool")?;
let requested = Ern::with_root("worker")?;

// Same child every time, regardless of when `requested` was minted
let child = parent.add_part(requested.name())?;
assert_eq!(child, parent.add_part(requested.name())?);

Returns an empty string for a root that carries no prefix, such as one built from a bare suffix or EntityRoot::default.

§Example
let root = EntityRoot::new("profile".to_string())?;

assert_eq!(root.name_str(), "profile");
assert!(root.as_str().starts_with("profile_"));
Source

pub fn new(value: String) -> Result<Self, ErnError>

Creates a new EntityRoot with the given value.

When value is a bare name, this method generates a time-ordered, unique identifier using the UUID v7 algorithm. Each call with the same name will generate a different ID, as it incorporates the current timestamp. This makes EntityRoot suitable for resources that should be ordered by creation time.

When value is already a fully-formed identifier, it is preserved verbatim so that existing roots survive a parse or deserialization round trip.

§Arguments
  • value - The string value to use as the base for the entity root ID
§Validation Rules
  • Value cannot be empty
  • Value must be between 1 and 255 characters
§Returns
  • Ok(EntityRoot) - If validation passes
  • Err(ErnError) - If validation fails
§Example
let root = EntityRoot::new("profile".to_string())?;

// The ID will contain the original name followed by a timestamp-based suffix
assert!(root.to_string().starts_with("profile_"));

// Re-creating from a formed identifier preserves it
let same = EntityRoot::new(root.to_string())?;
assert_eq!(root, same);

Trait Implementations§

Source§

impl AsRef<MagicTypeId> for EntityRoot

Source§

fn as_ref(&self) -> &MagicTypeId

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for EntityRoot

Source§

fn clone(&self) -> EntityRoot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EntityRoot

Source§

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

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

impl Default for EntityRoot

Source§

fn default() -> EntityRoot

Returns the “default value” for a type. Read more
Source§

impl Display for EntityRoot

Source§

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

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

impl Eq for EntityRoot

Source§

impl ErnComponent for EntityRoot

Source§

type NextState = Part

The type of the next component that should follow this one in the ERN structure. Read more
Source§

fn prefix() -> &'static str

Returns the prefix string that should appear before this component in an ERN. Read more
Source§

fn build_root(value: &str) -> Option<Result<EntityRoot, ErnError>>

Builds the ERN root component this type contributes, if it can occupy the root slot. Read more
Source§

impl From<EntityRoot> for MagicTypeId

Source§

fn from(value: EntityRoot) -> Self

Converts to this type from the input type.
Source§

impl From<MagicTypeId> for EntityRoot

Source§

fn from(value: MagicTypeId) -> Self

Converts to this type from the input type.
Source§

impl FromStr for EntityRoot

Implementation of FromStr for EntityRoot to create an entity root from a string.

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Creates an EntityRoot from a string.

A bare name receives a freshly minted, time-ordered v7 identifier, so each call with the same name yields a different ID. A string that is already a fully-formed identifier is preserved verbatim, which is what allows ErnParser to round-trip an ERN’s own Display output.

§Arguments
  • s - The string value to use as the base for the entity root ID
§Returns
  • Ok(EntityRoot) - If validation passes
  • Err(ErnError) - If validation fails
Source§

type Err = ErnError

The associated error which can be returned from parsing.
Source§

impl Hash for EntityRoot

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 PartialEq for EntityRoot

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for EntityRoot

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for EntityRoot

Auto Trait Implementations§

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.